【发布时间】:2017-07-30 09:58:44
【问题描述】:
假设我有这样的 Json 响应:
{
"status": true,
"data": {
"29": "Hardik sheth",
"30": "Kavit Gosvami"
}
}
我正在使用 Retrofit 来解析 Json 响应。根据this 的回答,我将不得不使用Map<String, String>,它将提供地图中的所有数据。现在我想要的是ArrayList<PojoObject>。
PojoObject.class
public class PojoObject {
private String mapKey, mapValue;
public String getMapKey() {
return mapKey;
}
public void setMapKey(String mapKey) {
this.mapKey = mapKey;
}
public String getMapValue() {
return mapValue;
}
public void setMapValue(String mapValue) {
this.mapValue = mapValue;
}
}
将Map<key,value> 转换为List<PojoObject> 的最佳方法是什么?
【问题讨论】:
-
你也有动态键吗?
-
@VivekMishra 是的
-
为什么首先需要一个列表?地图是更好的数据容器。无论如何,如果您真的需要它只是通过地图进行简单循环并为列表创建
PojoObject对象,那么这里到底有什么问题?