json格式字符串转化为json对象:
JObject calculate = (JObject)JsonConvert.DeserializeObject(Rep.Request["data"].ToString());
或者
JArray calculate = (JArray)JsonConvert.DeserializeObject(Rep.Request["data"].ToString());
JSON对象转化为json字符串:
string strResult = JsonConvert.SerializeObject(dtResult);
JArray是数组数据[{},{},{}],里面可以有多个JObject
JObject是json数据{}
取出里面的key和value用JToken
JObject json = //获得一个JObject对象
/*
{
"records": [
{
"ID": "ABC",
"OperationPatchID": "1",
"s05055396": "120.93900",
"s05055099": "14.44790",
"s04026131": "Open lot",
"s04020195": "3334",
"s03006029": "2014/7/23 0:00:00",
"s03006045": "BAC"
}
],
"count": 1
} Newtonsoft.Json.Linq.JObject
*/
StringBuilder sb = new StringBuilder("<div>");
JToken record = json["records"][0];
foreach(JProperty jp in record)
{
sb.Append(String.Format(@"<span>{0}</span>:<span>{1}</span>"
,jp.Name
,jp.Value));
}