Skip to content Skip to sidebar Skip to footer

Stuck On Parsing A Json Response To A Java Object In Android

I am making a query call to freebase and I receive a JSON response. The response has the following structure: { 'code': '/api/status/ok', 'result': [ { '/com

Solution 1:

I guess you can create a FreebaseResponse class that contains code, result (ArrayList<Person>), etc fields and use Gson to deserialize. the names that are not valid identifiers, e.g. /common/topic/image will be a problem. I haven't tried it myself but it seems to me that SerializedName annotation should do the trick.

Solution 2:

If you need all the fields, the way you mentioned seems to me like the way to go. If you only want a small part of the data, you can get it directly. In general, I think that since JSON is meant for object representation, it is better to create the appropriate class. It will ease your way in the future as well, as you will need more from this data.

Post a Comment for "Stuck On Parsing A Json Response To A Java Object In Android"