首页 > Web开发 > 详细

Newtonsoft.Json小记

时间:2016-07-06 17:58:19      阅读:317      评论:0      收藏:0      [点我收藏+]
            /*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"]);

 

Newtonsoft.Json小记

原文:http://www.cnblogs.com/changshuo/p/5647431.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!