来自以下link ,我需要获取存储在“media”中的值。
这是我的代码:
Content = Content.replace("jsonFlickrFeed(", "");
Content = Content.replace("})", "}");
jsonResponse = new JSONObject(Content);
JSONArray jsonMainNode = jsonResponse.optJSONArray("items"); // this works great!
但我无法访问过去的“项目”
最佳答案
您必须像这样循环遍历 JSON:
...
JSONArray jsonMainNode = jsonResponse.optJSONArray("items");
for (int i=0; i<jsonMainNode.length(); i++) {
String media = jsonMainNode.getJSONObject(i).getString("media");
}
这将循环遍历图像
并返回媒体
中的值。
在你的情况下应该是这样的:
..
JSONArray jsonMainNode = jsonResponse.optJSONArray("items");
for (int i=0; i<jsonMainNode.length(); i++) {
JSONObject finalNode = jsonMainNode.getJSONObject(i);
JSONArray finalArray = finalNode.optJSONArray("media");
for (int j=0; j<finalArray.length(); j++) {
String m = finalArray.getJSONObject(j).getString("m");
}
}
...因为media
节点内部还有另一个节点,称为m
。
关于java - json 解析新手 - 如何获取数组中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27206963/