首页 > 代码库 > json 多层序列化

json 多层序列化

  1. string jsonstr = "{\"Code\":1,\"Message\":[{\"merchant_id\":8,\"items\":[{\"count\":2,\"goods_name\":\"商品1  汉堡包22222\",\"goods_des\":\"汉堡包的描述  有什么好描述的\",\"goods_type\":1,\"price\":19.80,\"remark\":\"20元起送\",\"send_range\":\"周边一公里\",\"goods_id\":2,\"create_time\":\"2014-11-30 13:24:00\",\"update_time\":\"2014-11-30 13:24:00\",\"status\":1,\"user_name\":\"test123\"},{\"count\":2,\"goods_name\":\"商品1  汉堡包\",\"goods_des\":\"汉堡包的描述  有什么好描述的\",\"goods_type\":1,\"price\":19.80,\"remark\":\"20元起送\",\"send_range\":\"周边一公里\",\"goods_id\":1,\"create_time\":\"2014-11-30 13:24:43\",\"update_time\":\"2014-11-30 13:24:43\",\"status\":1,\"user_name\":\"test123\"}]}]}";  
  2.             JObject jo = (JObject)JsonConvert.DeserializeObject(jsonstr);  
  3.             Response.Write(jo["Code"].ToString());  
  4.             JArray jarry = JArray.Parse(jo["Message"].ToString());  
  5.             for (var i = 0; i < jarry.Count; i++)  
  6.             {  
  7.                 JObject j = JObject.Parse(jarry[i].ToString());  
  8.                 Response.Write(j["merchant_id"].ToString());  
  9.                 JArray jarry1 = JArray.Parse(j["items"].ToString());  
  10.                 for (var k = 0; k < jarry1.Count; k++)  
  11.                 {  
  12.                     JObject jk = JObject.Parse(jarry1[k].ToString());  
  13.                     Response.Write(jk["goods_name"].ToString());  
  14.                     Response.Write(jk["remark"].ToString());  
  15.                 }  
  16.             }

json 多层序列化