Newtonsoft.Json.Linq.JArray.Parse解析陣列
阿新 • • 發佈:2021-12-15
以下是遺傳json陣列:
var jsonInfo=[{"name":"abc","id":"1","count":0},{"name":"def","id":"2","count":1}]
如果使用傳統的JsonConvert.DeserializeObject方法會報錯,這時需要使用以下方法:
var arrdata = Newtonsoft.Json.Linq.JArray.Parse(jsoninfo);
List<UserInfo> obj2 = arrdata.ToObject<List<UserInfo>>();
string json = @"{ CPU: 'Intel', Drives: [ 'DVD read/writer', '500 gigabyte hard drive' ] }"; JObject o = JObject.Parse(json);
string json = @"[ 'Small', 'Medium', 'Large' ]"; JArray a = JArray.Parse(json);
using (StreamReader reader = File.OpenText(@"c:\person.json")) { JObject o = (JObject)JToken.ReadFrom(new JsonTextReader(reader)); // do stuff }
作者:Leo_wl 出處:http://www.cnblogs.com/Leo_wl/