C # to extract nested arrays json

json format more complex than the average as an array of points, as there are multiple levels of nesting, study a little, record the following code:

 
  string jsonText = "{'name':'test','phone':'18888888888','image':[{'name':'img1','data':'data1'},{'name':'img2','data':'data2'},{'name':'img3','data':'data3'}]}";
  JObject jo = (JObject)JsonConvert.DeserializeObject(jsonText);
  string zone = jo["name"].ToString();  string zone_en = jo["phone"].ToString();
  JArray jar = JArray.Parse(jo["image"].ToString());
  MessageBox.Show(zone);
  MessageBox.Show (zone_en);
  for (var i = 0; i < jar.Count; i++)
  {   

         JObject j = JObject.Parse(jar[i].ToString());

        MessageBox.Show(j["name"].ToString());
        MessageBox.Show(j["data"].ToString());
  }
 

The key is to use the JArray.Parse.

Guess you like

Origin www.cnblogs.com/kelly1314/p/12155019.html