Jak dekodować JSON z nieznanym polem za pomocą Gsona?
Mam JSON podobny do tego:
{
"unknown_field": {
"field1": "str",
"field2": "str",
"field3": "str",
"field4": "str",
"field5": "str"
}, ......
}
Stworzyłem klasy do mapowania tego jsona
public class MyModel implements Serializable {
private int id;
private HashMap<String, Model1> models;
// getters and setter for id and models here
}
a klasa Model1 jest klasą prostą tylko z polami String.
Ale to nie działa.
Edytować: theFormat JSON wygląda tak:
{
"1145": {
"cities_id": "1145",
"city": "Nawanshahr",
"city_path": "nawanshahr",
"region_id": "53",
"region_district_id": "381",
"country_id": "0",
"million": "0",
"population": null,
"region_name": "Punjab"
},
"1148": {
"cities_id": "1148",
"city": "Nimbahera",
"city_path": "nimbahera",
"region_id": "54",
"region_district_id": "528",
"country_id": "0",
"million": "0",
"population": null,
"region_name": "Rajasthan"
},
...
}