以下のjsonレスポンスから値を取得したい。最初のキーから値を取得できますが、別のキー オブジェクトからは取得できません。すべての URL の値を取得したいのですが、どの URL も動的でキーではありません。以下はjson応答です:
body、title、created_date の値を取得できます
{
"17": {
"27": {
"url": "some text here 1"
},
"28": {
"url": "some text here 12"
},
"29": {
"url": "some text here 123"
},
"title": "some text goes here",
"body": "Some text goes here",
"created_date": "1395386881"
}
}
私がしようとしているコードは以下の通りです:
try {
json = new JSONTokener(jsonNewsResponse).nextValue();
if (json instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) json;
Iterator<?> keys = jsonObject.keys();
while (keys.hasNext()) {
nid = String.valueOf(keys.next());
JSONObject jsonObj = jsonObject.getJSONObject(nid);
attributeValue = jsonObj.getString(attributeName);
List<String> listitems = new ArrayList<String>();
Iterator<?> key = jsonObj.keys();
while (key.hasNext()) {
String fid = String.valueOf(key.next());
System.out.println("FID"+fid);
System.out.println("FID"+fid);
System.out.println("FID"+fid);
System.out.println("FID"+fid);
JSONObject jObject = jsonObj.getJSONObject(fid);
listitems.add(jObject.getString("url"));
}
attachments = listitems.toArray(new String[0]);
}
}