当前位置:编程学习 > C#/ASP.NET >>

我用的是Newtonsoft.Json 不知道怎么解析Json字符串到对象---在线等待!!!!!

字符串是:


{"code":0,"ret":{"currentpage":"2","users":[{"baseinfo":{"易做图":"1","nickname":"\u8c01\u662f\u6211\u6700\u7231","age":"33","height":172,"education":"\u5927\u4e13","marital":"\u79bb\u5f02","income":"15000-20000","cityChn":"\u4e2d\u56fd","is_realname":"1"},"iconurl":"http:\/\/photo11.ddd.com\/2012\/11\/08\/120_150\/4B81D032F7B6113C666B1E0587F7C97B.jpg","longitude":"107.356507","latitude":"30.329715","uid":"75511718"},{"baseinfo":{"易做图":"1","nickname":"\u5510\u653f","age":"21","height":174,"education":"\u672c\u79d1","marital":"\u672a\u5a5a","income":"7000-10000","cityChn":"\u4e2d\u56fd","is_realname":"1"},"iconurl":"http:\/\/photo7.ddd.com\/2012\/07\/09\/120_150\/AC542E9A26E2C82F84419ED771EDD37B.jpg","longitude":"108.811730","latitude":"31.130584","uid":"69856161"},
.
..
.
.
.

]}}


要创建一个对应的类对象来解析。

结构应该是什么样的??




JSON 对象 --------------------编程问答--------------------
 json = json.Trim();
        if (json[0] != '[')
            json = "[" + json;
        if (json[json.Length - 1] != ']')
            json = json + "]";

        JavaScriptSerializer jss = new JavaScriptSerializer();
        ArrayList arrList = jss.Deserialize<ArrayList>(json);
        if (arrList.Count > 0)
        {
            foreach (Dictionary<string, object> arr in arrList)
            {
                  foreach (string key in arr.Keys)
                  {
                            //key就是属性
                                 //arr[key]就是对应的属性值
                  }
            }
        }
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,