Jobject 解析这个多层嵌套的json 需要获得type_id,hut_name,并且一一对应。

TonyLeeli 2016-04-21 08:49:18
["farm_id":"1002","hut_list":
[{"hut_id":"6","type_id":"5","hut_data_infor":
[{"hut_number":"1","hut_fieldid":"1","hut_name":"aaa","hut_layer_number":"1"}, {"hut_number":"17","hut_fieldid":"27","hut_name":"vv","hut_layer_number":"33"}
]},
{"hut_id":"7","type_id":"1","hut_data_infor":
[{"hut_number":"1","hut_fieldid":"14","hut_name":"a1","hut_layer_number":"1"},
{"hut_number":"2","hut_fieldid":"18","hut_name":"猩猩","hut_layer_number":"6"},

]}
]

求助啊!---------------------------------------------------__----__---_----_----__---__---__--__--_--_-_--_
...全文
707 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
TonyLeeli 2016-04-21
  • 打赏
  • 举报
回复
  public class Hutlist
        {
            public string farm_id { get; set; }
            public list_hut hut_list { get; set; }
        }
        public class list_hut
        {
            public int hut_id { get; set; }
            public int type_id { get; set; }
            public list_info hut_data_info { get;set; }
        }
        public class list_info
        {
            public string hut_number { get; set; }
            public string hut_fieldid { get; set; }
            public string hut_name { get; set; }
            public string hut_layer_number { get; set; }

        }
======= 实体类
TonyLeeli 2016-04-21
  • 打赏
  • 举报
回复
 JObject jsonObj = JObject.Parse(s);
            JArray jarry = JArray.Parse(jsonObj["hut_list"].ToString());
            for (int i = 0; i < jarry.Count;i++ )
            {
                JObject json = JObject.Parse(jarry[i].ToString());
                JArray jar = JArray.Parse(json["hut_data_info"].ToString());
                for (int j = 0; j < jar.Count;j++ )
                {
                    JObject jso = JObject.Parse(jar[j].ToString());
                    context.Response.Write(jso["hut_name"]);
                }
                context.Response.Write(json["type_id"]); 
            }
====== 这样解析 没有结果

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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