Newtonsoft.Json.Linq.JArray.Parse解析数组


Newtonsoft.Json解析数组

 

以下是遗传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
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM