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

APP开发王 2013-04-21 11:43:17
字符串是:


{"code":0,"ret":{"currentpage":"2","users":[{"baseinfo":{"sex":"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":{"sex":"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"},
.
..
.
.
.

]}}


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

结构应该是什么样的??




...全文
127 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
gxingmin 2013-04-21
  • 打赏
  • 举报
回复
 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]就是对应的属性值
                  }
            }
        }

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧