Trying to parse the following json using gson in my android app but givien it’s structure can’t work it out.
JSON
[
{
"city": {
"country": "Canada",
"id": 1,
"name": "Toronto",
"province": "Ontario"
}
},
{
"city": {
"country": "Canada",
"id": 11,
"name": "Ajax",
"province": "Ontario"
}
}
]
JAVA
public class LocationCityList {
private List<LocationCityContainer> cities;
public List<LocationCityContainer> getTrends() {
return cities;
}
public void setTrends(List<LocationCityContainer> cities) {
this.cities = cities;
}
}
The following returns an array of proper length but after that I can’t work out how to get city objects themselves.
Gson gson = new Gson();
Reader r = new InputStreamReader(getJSONData(url));
LocationCityList[] objs = gson.fromJson(r, LocationCityList[].class);
Any help much appreciated.
OK figured it out. Java code needs to be as follows.
}
}