求教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
[解决办法]
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);