I am trying to parse JSON using Retrofit and I am wondering if there is a way to skip or pass over the root object. Below is a snippet of the JSON.
{
"?xml": {
"@version": "1.0",
"@encoding": "utf-8"
},
"root": {
"uri": {
"#cdata-section": "http://api.bart.gov/api/stn.aspx?cmd=stns&json=y"
},
"stations": {
"station": [
{
"name": "12th St. Oakland City Center",
"abbr": "12TH",
"gtfs_latitude": "37.803768",
"gtfs_longitude": "-122.271450",
"address": "1245 Broadway",
"city": "Oakland",
"county": "alameda",
"state": "CA",
"zipcode": "94612"
},
{
"name": "West Oakland",
"abbr": "WOAK",
"gtfs_latitude": "37.804872",
"gtfs_longitude": "-122.295140",
"address": "1451 7th Street",
"city": "Oakland",
"county": "alameda",
"state": "CA",
"zipcode": "94607"
}
]
},
"message": ""
}
}
I have POJOs for root, stations, and station. I also have a StationList class that is listed below.
public class StationList {
private int id;
@SerializedName("root")
@Expose
private Root root;
public int getId() {return id;}
public Root getRoot() {
return root;
}
}
If I want to access the first station name ("12th St. Oakland City Center") I have to use this syntax
stationList.getRoot().getStations().getStation().get(0).getName()
Is there anyway It could be
stationList.getStation().get(0).getName();
I want to just ignore the root JSON object as I only want the list of stations.