Java实现JSON多层遍历

如以下的json串:"result":[{"appobranchid":"1","appobranchname":"银州办事处","content":[{"appocnt... 如以下的json串:
"result":[{"appobranchid":"1","appobranchname":"银州办事处","content":[{"appocnt":"5","appodate":"2019-01-07"},
{"appocnt":"5","appodate":"2019-01-08"},{"appocnt":"5","appodate":"2019-01-09"},
{"appocnt":"5","appodate":"2019-01-10"},{"appocnt":"5","appodate":"2019-01-11"}]},
{"appobranchid":"2","appobranchname":"新城区办事处","content":[{"appocnt":"5","appodate":"2019-01-07"},
{"appocnt":"5","appodate":"2019-01-08"},{"appocnt":"5","appodate":"2019-01-09"},{"appocnt":"5","appodate":"2019-01-10"},
{"appocnt":"5","appodate":"2019-01-11"}]},
{"appobranchid":"3","appobranchname":"开原办事处","content":[{"appocnt":"5","appodate":"2019-01-07"},{"appocnt":"5","appodate":"2019-01-08"},
{"appocnt":"5","appodate":"2019-01-09"},{"appocnt":"5","appodate":"2019-01-10"},{"appocnt":"5","appodate":"2019-01-11"}]},
{"appobranchid":"4","appobranchname":"昌图办事处","content":[{"appocnt":"5","appodate":"2019-01-07"},
{"appocnt":"5","appodate":"2019-01-08"},{"appocnt":"5","appodate":"2019-01-09"},{"appocnt":"5","appodate":"2019-01-10"},
{"appocnt":"5","appodate":"2019-01-11"}]},
{"appobranchid":"5","appobranchname":"西丰办事处","content":[{"appocnt":"5","appodate":"2019-01-07"},{"appocnt":"5","appodate":"2019-01-08"},
{"appocnt":"5","appodate":"2019-01-09"},{"appocnt":"5","appodate":"2019-01-10"},{"appocnt":"5","appodate":"2019-01-11"}]},
{"appobranchid":"6","appobranchname":"调兵山办事处","content":[{"appocnt":"5","appodate":"2019-01-07"},
{"appocnt":"5","appodate":"2019-01-08"},{"appocnt":"5","appodate":"2019-01-09"},{"appocnt":"5","appodate":"2019-01-10"},
{"appocnt":"5","appodate":"2019-01-11"}]},
{"appobranchid":"7","appobranchname":"清河办事处","content":[{"appocnt":"5","appodate":"2019-01-07"},{"appocnt":"5","appodate":"2019-01-08"},
{"appocnt":"5","appodate":"2019-01-09"},{"appocnt":"5","appodate":"2019-01-10"},{"appocnt":"5","appodate":"2019-01-11"}]}]

想要实现的效果是
1 银州办事处 5 2019-01-07 5 2019-01-08 5 2019-01-09 5 2019-01-10 5 2019-01-11
2 新城办事处 5 2019-01-07 5 2019-01-08 5 2019-01-09 5 2019-01-10 5 2019-01-11
3 开原办事处 ....

重金悬赏,跪求大佬解析
展开
 我来答
腾讯电脑管家
2019-01-05 · 百度知道官方认证企业
腾讯电脑管家
腾讯电脑管家是腾讯公司推出的免费安全管理软件,能有效预防和解决计算机上常见的安全风险,并帮助用户解决各种电脑“疑难杂症”、优化系统和网络环境,是中国综合能力最强、最稳定的安全软件。
向TA提问
展开全部
JSONObject jsonObject = new JSONObject(s);
然后用Iterator迭代器遍历取值,建议用反射机制解析到封装好的对象中
JSONObject jsonObject = new JSONObject(jsonString);
Iterator iterator = jsonObject.keys();while(iterator.hasNext()){
key = (String) iterator.next();
value = jsonObject.getString(key);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
302652034_bai
2019-01-05 · TA获得超过4145个赞
知道大有可为答主
回答量:2206
采纳率:66%
帮助的人:1539万
展开全部
String json=“”
JSONObject obj = new JSONObject(json);
JSONArray result = obj.getJSONArray("result");

for(int i=0;i<result.size();i++){
String r = "";
JSONObject app = result.getJSONObject(i);
String appobranchid = app.getString("appobranchid");
String appobranchname = app.getString("appobranchname");
r = appobranchid +" "+ appobranchname;
JSONArray arr = app.getJSONArray("content");
for(int j=0;j<arr.size();j++){
JSONObject content = arr.getJSONObject(i);
String appcnt = content.getString("appocnt");
String appdate = content.getString("appodate");
r += appcnt +" " + appdate;
}
System.out.println(r);
}
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
亢丰瑞
2019-01-05
知道答主
回答量:7
采纳率:0%
帮助的人:5283
展开全部
JSONObject jsonObject = new JSONObject(jsonString); Iterator iterator = jsonObject.keys(); while(iterator.hasNext()){ key = (String) iterator.next(); value = jsonObject.getString(key); }
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友c8fd32e
2019-01-05
知道答主
回答量:17
采纳率:0%
帮助的人:1.3万
展开全部
好红红火火恍恍惚惚哈哈哈哈哈哈哈我都没有
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式