JSON数据处理

1 .以下是json数据格式:
{ "errCode": 0, "index": 0, "info":
[
{ "devID": 0, "gpsInfoCounts": 1, "devGpsInfo":
[
{ "devID": 0, "gpsLat": 0, "gpsLng": 0, "gpsSpeed": 0, "gpsCourse": 0, "gpsStatus": 0, "gpsMileage": 0, "gpsStrDateTime": null,"gpsStrRecvDateTime": null, "gpsPower": 0, "gpsSignal": 0, "gpsOil": 0
}, null,
]
}, null,
]
}
循环 “devGpsInfo”的所有信息:
 1           var jobject = JObject.Parse(Webinfo);//Webinfo JSON 格式数据
 2             JArray jarry = JArray.Parse(jobject["info"].ToString());
 3             if (jarry.Count > 0)
 4             {
 5                 StringBuilder sendjson = new StringBuilder("[");
 6                 for (int i = 0; i < jarry.Count; i++)
 7                 {
 8                     JObject j = JObject.Parse(jarry[i].ToString());
 9                     JArray jarry1 = JArray.Parse(j["devGpsInfo"].ToString());
10                     for (var k = 0; k < jarry1.Count; k++)
11                     {
12                         JObject jk = JObject.Parse(jarry1[k].ToString());
13                         sendjson.Append("{'gpda_user_id':'" + jk["devID"].ToString() + "','gpda_recv_datetime':'" + jk["gpsStrRecvDateTime"].ToString() + "','gpda_latitude':'" +
14                                     jk["gpsLat"].ToString() + "','gpda_longitude':'" + jk["gpsLng"].ToString() + "','gpda_speed':'" + jk["gpsSpeed"].ToString() + "','gpda_course':'" + jk["gpsCourse"] + "','gpda_valid':'0" + "','current_status':'0" + "'},");
15                     }
16                 }
17                 sendjson.Append("]");
18          19             }

 



 

你可能感兴趣的:(JSON数据处理)