How should I make POJO
class? Object may have unlimited array.
This is my JSON
,
{
"result": {
"0": [{
"id": "51",
"first_name": "ra",
"last_name": "d",
"email": "raj@gmail.com",
"password": "1234",
"mobile_no": "8252536365",
"parent_id": "50",
"position": "0",
"type": "User",
"created_at": "1476447434",
"updated_at": "1476447434",
"deleted_at": null,
"stage": 0,
"total_childs": 0
}, {
"id": "52",
"first_name": "Ashish",
"last_name": "Chauhan",
"email": "ashish@mlm.com",
"password": "12345",
"mobile_no": "89889989832",
"parent_id": "8",
"position": "1",
"type": "admin",
"created_at": "1476702542",
"updated_at": "1476702542",
"deleted_at": null,
"stage": 0,
"total_childs": 0
}],
"2": [{
"id": "2",
"first_name": "Ashish",
"last_name": "Chauhan",
"email": "ashish@mlm.com",
"password": "12345",
"mobile_no": "89889989832",
"parent_id": "1",
"position": "0",
"type": "admin",
"created_at": "1475674631",
"updated_at": "1475674631",
"deleted_at": null,
"stage": 2,
"total_childs": 2
}],
"1": [{
"id": "7",
"first_name": "Shiva",
"last_name": "Singh",
"email": "shiva@mlm.com",
"password": "12345",
"mobile_no": "89889989832",
"parent_id": "2",
"position": "0",
"type": "user",
"created_at": "1475674808",
"updated_at": "1475674808",
"deleted_at": null,
"stage": 1,
"total_childs": 2
}, {
"id": "8",
"first_name": "Atul",
"last_name": "Kumar",
"email": "atul@mlm.com",
"password": "12345",
"mobile_no": "89889989832",
"parent_id": "2",
"position": "1",
"type": "user",
"created_at": "1475674835",
"updated_at": "1475674835",
"deleted_at": null,
"stage": 1,
"total_childs": 2
}]
}
}
If you are trying to form json response schema for retrofit:
Then in your api call:
And you can define resultResponse as:
ResultRespone.java:
then you can access individual results as:
You have dynamic keys in your JSON as "1", "2", "3" and so on.. So you have to use conecpt of key. Use JSONObject keys() to get the key and then iterate each key to get to the dynamic value.
This example will help you to understand what do you want to do .