1 string jsonText = "{‘name‘:‘test‘,‘phone‘:‘18888888888‘,‘image‘:[{‘name‘:‘img1‘,‘data‘:‘data1‘},{‘name‘:‘img2‘,‘data‘:‘data2‘},{‘name‘:‘img3‘,‘data‘:‘data3‘}]}"; 2 JObject jo = (JObject)JsonConvert.DeserializeObject(jsonText); 3 string zone = jo["name"].ToString(); 4 string zone_en = jo["phone"].ToString(); 5 JArray jar = JArray.Parse(jo["image"].ToString()); 6 MessageBox.Show(zone); 7 MessageBox.Show(zone_en); 8 for (var i = 0; i < jar.Count; i++) 9 { 10 JObject j = JObject.Parse(jar[i].ToString()); 11 MessageBox.Show(j["name"].ToString()); 12 MessageBox.Show(j["data"].ToString()); 13 }
引用 Newtonsoft.Json.dll 类库
主要调用 JObject 和 JArray对象
时间: 2024-10-10 01:21:41