using Newtonsoft.Json;
首先引用 Newtonsoft.Json;
定义一个字符串
string str = "[{'ID':8.0,'PAGEID':201.0,'TITLE':'我的主页','LNGTYPE':0.0,'FLAG':'1'}, {'ID':9.0,'PAGEID':201.0,'TITLE':'我的主页','LNGTYPE':0.0,'FLAG':'1'}]
string str1 = "{'ID':8.0,'PAGEID':201.0,'TITLE':'我的主页','LNGTYPE':0.0,'FLAG':'1'}";
将字符串转化为JArray
JArray ja = JsonConvert.DeserializeObject(str) as JArray;
将字符串转化为 JObject
JObject jo = JsonConvert.DeserializeObject(str1) as JObject ;
取值 ID
foreach(var a in ja) { var id = a["id"]; }
遍历jo中的键值
foreach (KeyValuePair<string, JToken> kvp in jo) { var jian = kvp.Key;//键 var zhi = kvp.value;//值 }