Reputation: 694
I have been trying to wrap my head around how to parse nested objects and arrays with GSON, still stuck. How can I parse the nested items listed in the "results" array?
{
"item": {
"results": [
{
"__metadata": {
"url": "google.com",
"type": "website"
},
"listed": true,
"market": 225,
"town": "Toronto"
},
{
"__metadata": {
"url": "twitter.com",
"type": "website"
},
"listed": true,
"market": 225,
"town": "Calgary"
}
]
}
}
How can I easily do this with GSON within Android?
Thank you!
Upvotes: 1
Views: 855
Reputation: 1768
Android Studio
Now create Gson object
Gson gson=new Gson();
Convert Json to java object
T obj = gson.fromJson(contents, tClass);
Now use this object "obj" to get values
Upvotes: 3