解析Json字符串跟解析Json数组

解析Json字符串我这边是使用了JObject的方法 需要引用一个类库

需要下载Newtonsoft.Json.rar dll

然后引用

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

第一个为解析字符串格式的Json

1 JObject jo = (JObject)JsonConvert.DeserializeObject(result);//result为要解析的字符串
2             string errcode = jo["errcode"].ToString();//[errcode]为解析字符串里面的字段 errcode为字段后面跟的值
3             string errmsg = jo["errmsg"].ToString();//同上
4             string recordresult = jo["recordresult"].ToString();//同上

第二个为解析字符串数组形式的Json

JArray jArray = (JArray)JsonConvert.DeserializeObject(recordresult);                string str = jArray[0]["checkType"].ToString();

本博客仅为自己记录使用不喜勿喷

原文地址:https://www.cnblogs.com/baimangguo/p/7613846.html