如何使用Gson解码具有未知字段的JSON?
如何使用Gson解码具有未知字段的JSON?
我有一个类似于这样的JSON数据:
{
"unknown_field": {
"field1": "str",
"field2": "str",
"field3": "str",
"field4": "str",
"field5": "str"
}, ......
}
我创建了用于映射这个JSON的类:
public class MyModel implements Serializable { private int id; private HashMapmodels; // 这里是id和models的getter和setter方法 }
而Model1类则只是一个只包含String字段的简单类。
但是它没有起作用。
编辑:这个JSON的格式看起来像这样:
{
"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"
},
...
}