[英]iterate through JSONArray in java
I have a JSONArray : 我有一个JSONArray:
public JSNArray getItems() {
JSONArray listjson = new JSONArray();
JSONObject fnl_json = new JSONObject();
//adding few items to fnl_json
listjson.add(fnl_json);
return fnal_json;
}
I am calling getItems function, how can I iterate through fnl_json from the called function? 我正在调用getItems函数,如何从调用的函数遍历fnl_json?
To iterate a JSONArray
you can do: 要迭代JSONArray
您可以执行以下操作:
JSONObject jsonObject = new JSONObject("jsonString");
JSONArray jsonArray = jsonObject.getJSONArray("arrayName");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject explrObject = jsonArray.getJSONObject(i); // you will get the json object
//do the stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.