Java实现JSON多层遍历
发布网友
发布时间:2022-04-23 04:34
我来回答
共4个回答
热心网友
时间:2022-04-23 19:40
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);
}
热心网友
时间:2022-04-23 20:58
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);
}
热心网友
时间:2022-04-23 22:33
JSONObject jsonObject = new JSONObject(jsonString); Iterator iterator = jsonObject.keys(); while(iterator.hasNext()){ key = (String) iterator.next(); value = jsonObject.getString(key); }
热心网友
时间:2022-04-24 00:24
好红红火火恍恍惚惚哈哈哈哈哈哈哈我都没有