{
"batchcomplete": "",
"warnings": {
"main": {
"*": "Unrecognized parameter: rvprop."
},
"extracts": {
"*": "\"exlimit\" was too large for a whole article extracts request, lowered to 1."
}
},
"query": {
"normalized": [
{
"from": "pune",
"to": "Pune"
}
],
"pages": {
"164634": {
"pageid": 164634,
"ns": 0,
"title": "Pune",
"extract": ""
}
}
}
}
<小时/>
在上面的 json 中,“pages”对象内的数字键是动态的。那么我如何为这个json制作一个pojo。
拜托,拜托,请帮助我。 我对此进行了很多搜索,但没有任何有效的方法。 另外我是 retrofit 新手,请详细回答。 我看到一些答案提到在这种情况下使用 map (例如 Parse Dynamic Key Json String using Retrofit )。但这些答案没有得到适当的阐述。请帮我彻底理解它。
最佳答案
您可以在 Pages
类中使用 hashmap
来获取其他属性/动态属性
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
关于java - 如何使用动态键为 json 创建 POJO 类以进行改造?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44844226/