Como decodificar JSON com campo desconhecido usando o Gson?
Eu tenho JSON semelhante a este:
{
"unknown_field": {
"field1": "str",
"field2": "str",
"field3": "str",
"field4": "str",
"field5": "str"
}, ......
}
Eu criei classes para mapear este json
public class MyModel implements Serializable {
private int id;
private HashMap<String, Model1> models;
// getters and setter for id and models here
}
e a classe Model1 é uma classe simples apenas com campos String.
Mas isso não funciona.
Editar: aFormato JSON se parece com isso:
{
"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"
},
...
}