1.将json字符串解析成指定对象
string guiddata ="带解析的数据"; //序列化数据 GuidResult model = JsonConvert.DeserializeObject<GuidResult>(guiddata);
1 public class GuidResult 2 { 3 public GuidData data { get; set; } 4 public bool success { get; set; } 5 public string msg { get; set; } 6 }
2.将json字符串解析成数组
1 var jsonInfo=[{"name":"abc","id":"1","count":0},{"name":"def","id":"2","count":1}] 2 3 //如果使用传统的JsonConvert.DeserializeObject方法会报错,这时需要使用以下方法: 4 var arrdata = Newtonsoft.Json.Linq.JArray.Parse(jsoninfo); 5 List<UserInfo> obj2 = arrdata.ToObject<List<UserInfo>>();