使用Newtonsoft处理Json方法

引用的命名空间

using Newtonsoft.Json;using Newtonsoft.Json.Linq;

示例:

//获取城市坐标public string GetLocation(string city) { string url = "http://gc.ditu.aliyun.com/geocoding?a=济南市"; //string url = "http://gc.ditu.aliyun.com/geocoding?a="+city; var result = new WebClient().DownloadString(url); JObject jresult = (JObject)JsonConvert.DeserializeObject(result); var lat= jresult["lat"].ToString(); var lon= jresult["lon"].ToString(); return lat+","+lon; }

 

同类json序列化的使用:http://ashui.net/archives/2015/1097.html