利用Newtonsoft.Json反序列解析。
参考案例:HD_Maps.aspx获得IP当地地理经纬坐标
json:
{"address":"CN|\u5b89\u5fbd|\u829c\u6e56|None|CHINANET|0|0","content":{"address":"\u5b89\u5fbd\u7701\u829c\u6e56\u5e02","address_detail":{"city":"\u829c\u6e56\u5e02","city_code":129,"district":"","province":"\u5b89\u5fbd\u7701","street":"","street_number":""},"point":{"x":"118.38410842","y":"31.36601979"}},"status":0}
根据json字符串值建立规则类
public class JsonParser
{
public Content content { get; set; }
}
public class Content
{
public Point point { get; set; }
}
public class Point
{
public string x { get; set; }
public string y { get; set; }
}
如果不会设计C#类,可以把JSON字符串复制到网址:http://json2csharp.chahuo.com/,自动生成JSON
主程序:
//JsonParser为自定义类
JsonParser jp = (JsonParser)JsonConvert.DeserializeObject<JsonParser>(jsonStr);
// 根据自定义类获取指定值
xy = jp.content.point.x +","+jp.content.point.y;
|