I want to parse following JSON data in Android Studio using Gson library. But the data is generic..dont know what keys(objects) are come in data..
under school object - there is number 1103 which is object.
and under that object we have shoolname, shortname, students again under students - there are id's like 2201, 2202... these objects are dynamic dont know what comes in response..
so question is how to parse this json string in android using Gson?
or any other solution for that is welcome
{
"schools": {
"home": "1103",
"statelevel": "1348"
},
"school": {
"1103": {
"schoolname": "Indira School",
"nameshort": "ind",
"students": {
"2201": {
"name": "Ritesh",
"isCR": true,
"maths": {
"score": 95,
"lastscore": 86
}
},
"2202": {
"name": "Sanket",
"maths": {
"score": 98,
"lastscore": 90
}
},
"2203": {
"name": "Ajit",
"maths": {
"score": 94,
"lastscore": 87
}
}
}
},
"1348": {
"schoolname": "Patil School",
"nameshort": "pat",
"students": {
"3201": {
"name": "Ravi",
"maths": {
"score": 95,
"lastscore": 86
}
},
"3202": {
"name": "Raj",
"isCR": true,
"maths": {
"score": 98,
"lastscore": 90
}
},
"3203": {
"name": "Ram",
"maths": {
"score": 94,
"lastscore": 87
}
}
}
}
}
}
I have refered the How to parse dynamic JSON fields with GSON?.. but not worked in my case..i have inner generic classes too.
- I have found the solution here https://stackoverflow.com/a/23473650/7790252. implements deserializer to model classes like school and students.