首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求教C#解析json字符串解决方法

2013-08-29 
求教C#解析json字符串{results : [{address_components : [{long_name : Laiwu,short_name : L

求教C#解析json字符串
{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "Laiwu",
               "short_name" : "Laiwu",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Shandong",
               "short_name" : "Shandong",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "China",
               "short_name" : "CN",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Laiwu, Shandong, China",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 36.5538547,
                  "lng" : 117.9753321
               },
               "southwest" : {
                  "lat" : 35.9906212,


                  "lng" : 117.3391437
               }
            },
            "location" : {10:11 2013/8/18
               "lat" : 36.213691,
               "lng" : 117.676731
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 36.2978434,
                  "lng" : 117.8118896
               },
               "southwest" : {
                  "lat" : 36.12000390000001,
                  "lng" : 117.5489044
               }
            }
         },
         "types" : [ "locality", "political" ]
      }
   ],
   "status" : "OK"
}
怎样将location中lat和lng的值提取出来?网上说使用newtonsoft,没看明白,求大神

[解决办法]
refer : http://blog.csdn.net/chinacsharper/article/details/9246627


[解决办法]

引用:
Quote: 引用:

如果只要将location中lat和lng的值提取出来,可以不反序列化的,用正则表达式:

 "^"location"(.*?)"lat" : (.*?),"lng" : (.*?)},$"

刚试了,不对啊


string json = "{"results":[{"address_components":[{"long_name":"Laiwu","short_name":"Laiwu","types":["locality","political"]},{"long_name":"Shandong","short_name":"Shandong","types":["administrative_area_level_1","political"]},{"long_name":"China","short_name":"CN","types":["country","political"]}],"formatted_address":"Laiwu,Shandong,China","geometry":{"bounds":{"northeast":{"lat":36.5538547,"lng":117.9753321},"southwest":{"lat":35.9906212,"lng":117.3391437}},"location":{10:112013/8/18"lat":36.213691,"lng":117.676731},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":36.2978434,"lng":117.8118896},"southwest":{"lat":36.12000390000001,"lng":117.5489044}}},"types":["locality","political"]}],"status":"OK"}";


Regex r = new Regex(""location"(.*?)"lat"(.*?),"lng"(.*?)},");
Console.WriteLine(r.Matches(json)[0].Value);

热点排行