I’ve a json output which returns something like this :
[
{
"title":"facebook",
"description":"social networking website",
"url":"http://www.facebook.com"
},
{
"title":"WoW",
"description":"game",
"url":"http://us.battle.net/wow/"
},
{
"title":"google",
"description":"search engine",
"url":"http://www.google.com"
}
]
I am familiar with parsing json having the title object, but i’ve no clue about how to parse the above json as it is missing the title object. Can you please provide me with some hints/examples so i can check them and work on parsing the above code?
Note : I’ve checked a similar example here but it doesn’t have a satisfactory solution.
Your JSON is an array of objects.
The whole idea around
Gson(and other JSON serialization/deserialization) libraries is that you wind up with your own POJOs in the end.Here’s how to create a POJO that represents the object contained in the array and get a
Listof them from that JSON:Output:
Edit to add: Because the JSON is an array of things, the use of the
TypeTokenis required to get to aListbecause generics are involved. You could actually do the following without it:You now have an array of your
WebsiteInfoobjects from one line of code. That being said, using a genericCollectionorListas demonstrated is far more flexible and generally recommended.You can read more about this in the Gson users guide