标签:
将DataSet转换成Json: private string GetJsonAddress() { string result = ""; string sql = "SELECT ms.ID, ms.SchoolAddress FROM MiddleSchool ms WHERE ms.[Status]=1 AND ms.SchoolAddress !=‘‘ AND ms.SchoolAddress IS NOT NULL "; DataSet ds=DbHelperSQL.Query(sql); result=Newtonsoft.Json.JsonConvert.SerializeObject(ds.Tables[0]); return result; } 解析Json: private void UpdateMiddleSchoolLatLng() { VPEA.BLL.MiddleSchool msBLL = new VPEA.BLL.MiddleSchool(); VPEA.Model.MiddleSchool msModel = null; string jsonArray = hdn2.Value; JArray ja = (JArray)JsonConvert.DeserializeObject(jsonArray); for (int i = 0; i < ja.Count; i++) { Response.Write("===" + ja[i]["ID"] + "---lat:" + ja[i]["lat"] + "==="+"lng:" + ja[i]["lng"] + "<br>"); msModel = msBLL.GetModel((Int32)ja[i]["ID"]); msModel.Lat = ja[i]["lat"].ToString(); msModel.Lng = ja[i]["lng"].ToString(); msBLL.Update(msModel); } } //解析json数组 string jsonArrayText1 ="[{‘a‘:‘a1‘,‘b‘:‘b1‘},{‘a‘:‘a2‘,‘b‘:‘b2‘}]"; JArray ja =(JArray)JsonConvert.DeserializeObject(jsonArrayText1); string ja1a =ja[1]["a"].ToString(); //解析JSON对象: string jsonText ="{\"beijing\":{\"zone\":\"海淀\",\"zone_en\":\"haidian\"}}"; JObject jo =(JObject)JsonConvert.DeserializeObject(jsonText); string zone =jo["beijing"]["zone"].ToString(); string zone_en =jo["beijing"]["zone_en"].ToString();
标签:
原文地址:http://www.cnblogs.com/panqingqiang/p/4651471.html