【发布时间】:2015-03-10 09:50:51
【问题描述】:
我正在尝试在我的 android 应用程序中使用 gson 解析以下响应:
{
"richerich":{
"id":19250176,
"name":"RichERich",
"profileIconId":744,
"summonerLevel":30,
"revisionDate":1425977347000
}
"alma":{
"id":19250174,
"name":"Alma",
"profileIconId":764,
"summonerLevel":30,
"revisionDate":14259773423424
}
}
键“richeric”是一个动态键,可能会改变,我也可以在我的响应字符串中包含其他响应对象,例如“richeric”。
我为此创建了类:
public class SummonerDto {
private long id;
private String name;
private int profileIconId;
private long revisionDate;
private long summonerLevel;
//getters, setters...
}
和我的响应类:
public class SummonerInfoResponse {
private Map<String, SummonerDto> summoners;
public Map<String, SummonerDto> getSummoners() {
return summoners;
}
public void setSummoners(Map<String, SummonerDto> summoners) {
this.summoners = summoners;
}
}
我使用以下代码:
return gson.fromJson(response, SummonerInfoResponse.class);
但它返回空值。谁能告诉我为什么?
谢谢。
【问题讨论】:
-
如果您仍然没有得到答案,请告诉我
-
而不是私人地图
召唤师;尝试使用私人 SummonerD 来召唤召唤者; -
@ThePavolC 不,也不行
-
@PankajNimgade 我还是没有得到答案