using Newtonsoft.Json;
首先引用 Newtonsoft.Json;blog
定義一個字符串字符串
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'}";
將字符串轉化爲JArraystring
JArray ja = JsonConvert.DeserializeObject(str) as JArray;
將字符串轉化爲 JObjectclass
JObject jo = JsonConvert.DeserializeObject(str1) as JObject ;
取值 IDforeach
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;//值 }