您的位置:首页 > Web前端 > JavaScript

JSON浅析

2016-05-17 08:40 411 查看
一、JSON的创建

JSON类:JObject、JArray、JValue、JProperty(key/value)、JToken

1、JSON对象的创建

private JObject CreateJSON()
{
JObject pObject = new JObject();
pObject["name"] = this.txtName.Text.Trim();
pObject["addressAll"] = "";
pObject["lon"] = this.txtCoordX.Text.Trim();
pObject["lat"] = this.txtCoordY.Text.Trim();
pObject["geotext"] = "";
pObject["cityCode"] = "360700";
pObject["type_code"] = "030003";
pObject["creator"] = "";
pObject["province_name"] = this.cmbRegion1st.Text.Trim();
pObject["city_name"] = this.cmbRegionSecond.Text.Trim();
pObject["county_name"] = this.txtRegionThird.Text.Trim();
pObject["town_name"] = this.txtRegion4th.Text.Trim();
pObject["lat"] = this.txtCoordY.Text.Trim();
pObject["village"] = this.txtRegion5th.Text.Trim();
pObject["street"] = this.txtAddress.Text.Trim();
pObject["streetNum"] = "";
pObject["street_suffix"] = "";
pObject["community"] = this.txtResidentName.Text.Trim();
pObject["communitySuf"] = this.txtResidentSuffix.Text.Trim();
pObject["buildNum"] = "";
pObject["buildSuf"] = "";
pObject["landmark"] = this.txtLandmark.Text.Trim();
pObject["lm_suffix"] = this.txtLandmarkSuffix.Text.Trim();
return Object;
}


JObject.Parse(string json);

JObject.FromObject(object o);

JObject.Load(JsonReader reader).

2、JSON数值的创建

private JArray CreateJSON()
{
JObject pObject = new JObject();
pObject["name"] = this.txtName.Text.Trim();

JArray jArray = new JArray();
jArray.Add(pObject);

return jArray ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息