Asp.Net解析没有Key的JSON数据对象

¥15.00

项目中碰到一个奇怪的需求,有一段json的行政区域数据,但是没有Key,不知道该如何使用.Net进行解析操作。JSON数据如下:

{"北京":["北京"],"天津":["天津"],"山西":["太原","大同","阳泉","长治","晋城","朔州","晋中","运城","忻州","临汾","吕梁"],"内蒙古":["呼和浩特","包头","乌海","赤峰","通辽","鄂尔多斯","呼伦贝尔","巴彦淖尔","乌兰察布","兴安","锡林郭勒","阿拉善"],"辽宁":["沈阳","大连","鞍山","抚顺","本溪","丹东","锦州","营口","阜新","辽阳","盘锦","铁岭","朝阳","葫芦岛"],"吉林":["长春","吉林","四平","辽源","通化","白山","白城","松原","延边","长白山","梅河口","公主岭"],"黑龙江":["哈尔滨","齐齐哈尔","鸡西","鹤岗","双鸭山","大庆","伊春","佳木斯","七台河","牡丹江","黑河","绥化","大兴安岭","绥芬河","抚远"],"上海":["上海"],"江苏":["南京","无锡","徐州","常州","苏州","南通","连云港","淮安","盐城","扬州","镇江","泰州","宿迁"],"浙江":["杭州","宁波","温州","嘉兴","湖州","绍兴","金华","衢州","舟山","台州","丽水"],"安徽":["合肥","宿州","淮北","阜阳","蚌埠","淮南","滁州","马鞍山","芜湖","铜陵","安庆","黄山","六安","池州","宣城","亳州"],"福建":["福州","厦门","莆田","三明","泉州","漳州","南平","龙岩","宁德","平潭"],"江西":["南昌","九江","上饶","抚州","宜春","吉安","赣州","景德镇","萍乡","新余","鹰潭"],"山东":["济南","青岛","淄博","枣庄","东营","烟台","潍坊","济宁","泰安","威海","日照","莱芜","临沂","德州","聊城","滨州","菏泽"],"河南":["郑州","开封","洛阳","平顶山","安阳","鹤壁","新乡","焦作","濮阳","许昌","漯河","三门峡","南阳","商丘","周口","信阳","驻马店","济源"],"河北":["石家庄","唐山","秦皇岛","邯郸","邢台","保定","张家口","承德","沧州","廊坊","衡水","定州","辛集"],"湖北":["武汉","黄石","十堰","宜昌","襄阳","鄂州","荆门","孝感","荆州","黄冈","咸宁","随州","恩施","仙桃","潜江","天门","神农架"],"湖南":["长沙","株洲","湘潭","衡阳","邵阳","岳阳","常德","张家界","益阳","郴州","永州","怀化","娄底","湘西"],"广东":["广州","深圳","珠海","汕头","佛山","韶关","湛江","肇庆","江门","茂名","惠州","梅州","汕尾","河源","阳江","清远","东莞","中山","潮州","揭阳","云浮"],"海南":["海口","三亚","三沙","儋州","其他"],"重庆":[&
            

最佳解决方案

Asp.Net中解析没有Key的JSON数据,也就是无法生成相应实体对象的数据的时候,一般按照字符串来处理,使用Dictionary来接受反序列后的对象。要解析你的数据,接受反序列化后的数据对象可以用 Dictionary<string, string[]>  ,代码参考如下:

    string area = "{\"北京\":[\"北京\"],\"天津\":[\"天津\"],\"山西\":[\"太原\",\"大同\",\"阳泉\",\"长治\",\"晋城\",\"朔州\",\"晋中\",\"运城\",\"忻州\",\"临汾\",\"吕梁\"],\"内蒙古\":[\"呼和浩特\",\"包头\",\"乌海\",\"赤峰\",\"通辽\",\"鄂尔多斯\",\"呼伦贝尔\",\"巴彦淖尔\",\"乌兰察布\",\"兴安\",\"锡林郭勒\",\"阿拉善\"],\"辽宁\":[\"沈阳\",\"大连\",\"鞍山\",\"抚顺\",\"本溪\",\"丹东\",\"锦州\",\"营口\",\"阜新\",\"辽阳\",\"盘锦\",\"铁岭\",\"朝阳\",\"葫芦岛\"],\"吉林\":[\"长春\",\"吉林\",\"四平\",\"辽源\",\"通化\",\"白山\",\"白城\",\"松原\",\"延边\",\"长白山\",\"梅河口\",\"公主岭\"],\"黑龙江\":[\"哈尔滨\",\"齐齐哈尔\",\"鸡西\",\"鹤岗\",\"双鸭山\",\"大庆\",\"伊春\",\"佳木斯\",\"七台河\",\"牡丹江\",\"黑河\",\"绥化\",\"大兴安岭\",\"绥芬河\",\"抚远\"],\"上海\":[\"上海\"],\"江苏\":[\"南京\",\"无锡\",\"徐州\",\"常州\",\"苏州\",\"南通\",\"连云港\",\"淮安\",\"盐城\",\"扬州\",\"镇江\",\"泰州\",\"宿迁\"],\"浙江\":[\"杭州\",\"宁波\",\"温州\",\"嘉兴\",\"湖州\",\"绍兴\",\"金华\",\"衢州\",\"舟山\",\"台州\",\"丽水\"],\"安徽\":[\"合肥\",\"宿州\",\"淮北\",\"阜阳\",\"蚌埠\",\"淮南\",\"滁州\",\"马鞍山\",\"芜湖\",\"铜陵\",\"安庆\",\"黄山\",\"六安\",\"池州\",\"宣城\",\"亳州\"],\"福建\":[\"福州\",\"厦门\",\"莆田\",\"三明\",\"泉州\",\"漳州\",\"南平\",\"龙岩\",\"宁德\",\"平潭\"],\"江西\":[\"南昌\",\"九江\",\"上饶\",\"抚州\",\"宜春\",\"吉安\",\"赣州\",\"景德镇\",\"萍乡\",\"新余\",\"鹰潭\"],\"山东\":[\"济南\",\"青岛\",\"淄博\",\"枣庄\",\"东营\",\"烟台\",\"潍坊\",\"济宁\",\"泰安\",\"威海\",\"日照\",\"莱芜\",\"临沂\",\"德州\",\"聊城\",\"滨州\",\"菏泽\"],\"河南\":[\"郑州\",\"开封\",\"洛阳\",\"平顶山\",\"安阳\",\"鹤壁\",\"新乡\",\"焦作\",\"濮阳\",\"许昌\",\"漯河\",\"三门峡\",\"南阳\",\"商丘\",\"周口\",\"信阳\",\"驻马店\",\"济源\"],\"河北\":[\"石家庄\",\"唐山\",\"秦皇岛\",\"邯郸\",\"邢台\",\"保定\",\"张家口\",\"承德\",\"沧州\",\"廊坊\",\"衡水\",\"定州\",\"辛集\"],\"湖北\":[\"武汉\",\"黄石\",\"十堰\",\"宜昌\",\"襄阳\",\"鄂州\",\"荆门\",\"孝感\",\"荆州\",\"黄冈\",\"咸宁\",\"随州\",\"恩施\",\"仙桃\",\"潜江\",\"天门\",\"神农架\"],\"湖南\":[\"长沙\",\"株洲\",\"湘潭\",\"衡阳\",\"邵阳\&qu
                        

hierror T4 被采纳率73%
2020-11-09 09:05
打赏 0 0
页面统计
402 访问
0 帮助
0.00 打赏

hierror 2019 © hierror.com 京ICP备13026190号-1

通知消息
  • 暂无任何消息