Json数组,Newtonsoft.Json应用
作者:互联网
Json越来越流行,而Newtonsoft.Json是处理Json的强大工具,客户端返回的数据为
{"Data": [{"out_put":"01","hosting":"Z01_HOS_253_M1","value":185}, {"out_put":"02","hosting":"Z01_HOS_253_M1","value":0}, {"out_put":"01","hosting":"Z01_HOS_256_M1","value":1662}, {"out_put":"02","hosting":"Z01_HOS_256_M1","value":29}, {"out_put":"01","hosting":"Z01_HOS_251_M1","value":3646}]}
创建类Tr_Lift_Big,表示每行记录
class Tr_Lift_Big { public string out_put { get; set;} public string hosting { get; set; } public int value { get; set; } }
处理每个对象的代码
JObject jsonObj; jsonObj = JObject.Parse("{\"Data\":。。。6}]}"); JArray jsonArray = JArray.Parse(jsonObj["Data"].ToString()); List<Tr_Lift_Big> liftList = new List<Tr_Lift_Big>(); liftList = JsonConvert.DeserializeObject<List<Tr_Lift_Big>>(jsonArray.ToString()); int mValue; for (int i = 0; i < liftList.Count; ++i) { mValue = liftList[i].value; }
标签:Newtonsoft,Z01,hosting,value,Json,数组,put,out 来源: https://www.cnblogs.com/imhuanxi/p/13924774.html