Friday, 27 September 2013

Parsing nested Json objects without keys using Gson

Parsing nested Json objects without keys using Gson

I have a json with this format
{
"lines" : {
"0" : "Hammersmith & City",
"1" : "Circle"
},
"id" : "233",
"name" : "Shepherd's Bush Market"
}, {
"lines" : {
"0" : "Hammersmith & City",
"1" : "Circle"
},
"id" : "233",
"name" : "Shepherd's Bush Market"
}, {
"lines" : {
"0" : "Hammersmith & City",
"1" : "Circle"
},
"id" : "233",
"name" : "Shepherd's Bush Market"
}
Normally I could create an object like this
public class MyObject {
public String id;
public String name;
public Line[] lines;
public class Line {
public String key;
public String value;
}
}
And the Gson serializer would handle the parsing but in this case the
lines object doesn't have any keys/ids. I have tried using HashMaps and
Maps instead of inner classes but it doesn't work. Is there a way I can
parse this using Gson?

No comments:

Post a Comment