1、添加引用Newtonsoft.Json.dll 2、具體代碼: ...
1、添加引用Newtonsoft.Json.dll
using Newtonsoft.Json.Linq;
2、具體代碼:
1 StreamReader sr = new StreamReader("D:\\" + "****" + ".txt"); 2 String data = sr.ReadToEnd(); 3 //data ="{\r\n\t\"Data\": [{\r\n\t\t\t\"dwdm\": \"1020031077\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"dwdm\": \"1020120426\"\r\n\t\t}]\r\n}" 4 data = data.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty);//去除空格 5 JObject studentsJson = JObject.Parse(data); 6 var studentsList = studentsJson["Data"].AsEnumerable(); 7 string a = ""; 8 foreach (var item in studentsList) 9 { 10 a = item["dwdm"].ToString(); 11 } 12 return a;