I know this has been asked many times but none of the solution provided is working in my case.
Here is my JSON which I am getting as a response from a webservice
{
"size": 1,
"_links": {
"context": "XXXX",
"self": "XXXXXX",
"base": "XXXXXX"
},
"start": 0,
"limit": 50,
"results": [
{
"container": {
"extensions": {
"position": "none"
},
"_links": {
"webui": "XXXX",
"tinyui": "XXXX",
"self": "XXXXXX"
},
"id": "XXXXX",
"type": "page",
"title": "XXXXX",
"_expandable": {
"container": "XXXXX",
"metadata": "",
"operations": "",
"children": "XXXX/child",
"history": "XXXX/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "XXXXX/descendant",
"space": "XXXXX"
},
"status": "current"
},
"metadata": {
"mediaType": "text/plain",
"comment": ""
},
"extensions": {
"fileSize": 8,
"mediaType": "text/plain",
"comment": ""
},
"_links": {
"download": "/download/attachments/XXXXX/MyData1.txt?version=1&modificationDate=1483652732000&api=v2",
"webui": "XXXXX",
"self": "XXXXX"
},
"id": "attXXXXXX",
"type": "attachment",
"title": "MyData1.txt",
"_expandable": {
"operations": "",
"children": "XXXX",
"history": "XXXXX",
"ancestors": "",
"body": "",
"descendants": "XXXXX",
"space": "XXXXX"
},
"version": {
"number": 1,
"minorEdit": false,
"by": {
"profilePicture": {
"path": "XXXXX",
"isDefault": true,
"width": 48,
"height": 48
},
"displayName": "XXXXX",
"type": "known",
"userKey": "XXXXX",
"username": "XXXXX"
},
"message": "",
"when": "2017-01-05T16:45:32.000-05:00"
},
"status": "current"
}
]
}
I need to find the value of the id which is attXXXXXX and here is my code.
JSONObject page = new JSONObject(pageObj);
JSONArray jsonArray= page.getJSONArray("results");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject explrObject = jsonArray.getJSONObject(i);
}
But the above loop just runs once as the lenght of the jsonArray is 1. All the solution provided in other posts are the same i.e. iterating over the json array. Am I missing something ? Suggestion ?