/*json相关*/ //http://www.cnblogs.com/hongfei/p/3593936.html string jsonObject = "{\"phone\":\"18694990884\",\"codeType\":\"register\"}"; JObject jo = JObject.Parse(jsonObject); //JObject遍历json的key和value foreach (var item in jo) { Console.WriteLine(item.Key + ":" + item.Value + ","); } //JArray遍历 string jsonArray = "[{‘a‘:‘a1‘,‘b‘:‘b1‘},{‘a‘:‘a2‘,‘b‘:‘b2‘}]"; JArray ja = JArray.Parse(jsonArray); foreach (JObject j in ja) { foreach (var item in j) { Console.WriteLine(item.Key); } } //json嵌套 string jsonText = "{\"beijing\":{\"zone\":\"海淀\",\"zone_en\":\"haidian\"}}"; jo = JObject.Parse(jsonText); Console.WriteLine("key取值:" + jo["beijing"]["zone"] + ";索引:" + ja[0]["a"]);
时间: 2024-10-11 04:09:23