码迷,mamicode.com
首页 > Windows程序 > 详细

c# json 解析

时间:2015-07-16 18:26:02      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

将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();

 

c# json 解析

标签:

原文地址:http://www.cnblogs.com/panqingqiang/p/4651471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!