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 开原办事处 ....
重金悬赏,跪求大佬解析 展开
"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);
}
然后用Iterator迭代器遍历取值,建议用反射机制解析到封装好的对象中
JSONObject jsonObject = new JSONObject(jsonString);
Iterator iterator = jsonObject.keys();while(iterator.hasNext()){
key = (String) iterator.next();
value = jsonObject.getString(key);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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);
}
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);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JSONObject jsonObject = new JSONObject(jsonString); Iterator iterator = jsonObject.keys(); while(iterator.hasNext()){ key = (String) iterator.next(); value = jsonObject.getString(key); }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
好红红火火恍恍惚惚哈哈哈哈哈哈哈我都没有
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询