我有以下结构的JSON数据。我曾尝试创建具有相同结构和相同名称的POJO。我带了一个DTO,其中包含一个列表(DTO的结构中的数字对象在下面的JSON中)和一个String“Notice”。我无法获得DTO中的数据。无法解析JSON数据到POJO
{
"notice": "This API is in a pre-launch state, and will go through significant changes.",
"1": {
"next_renewal_date": "2014-08-01",
"next_renewal_fee": {
"price": "800.0",
"currency": "USD"
},
"next_renewal_description": "1st Annuity - Official Fee",
"next_per_claim_fee": {
"price": "0.0",
"currency": "USD",
"free_claims": 0,
"claim_type": "claims_count"
},
"next_agent_fee": {
"price": "0.0",
"currency": "USD"
},
"grace_period_end_date": "2015-02-01"
},
"2": {
"next_renewal_date": "2018-08-01",
"next_renewal_fee": {
"price": "1800.0",
"currency": "USD"
},
"next_renewal_description": "2nd Annuity - Official Fee",
"next_per_claim_fee": {
"price": "0.0",
"currency": "USD",
"free_claims": 0,
"claim_type": "claims_count"
},
"next_agent_fee": {
"price": "0.0",
"currency": "USD"
},
"grace_period_end_date": "2019-02-01"
}
}
POJO:
public class RenewalAPICallListDTO {
private Map<Integer,JSONCallDto> apiCallList;
public Map<Integer, JSONCallDto> getApiCallList() {
return apiCallList;
}
public void setApiCallList(Map<Integer, JSONCallDto> apiCallList) {
this.apiCallList = apiCallList;
}
private String notice;
public String getNotice() {
return notice;
}
public void setNotice(String notice) {
this.notice = notice;
}
}
方法调用:
Gson gson = new Gson();
RenewalAPICallListDTO respDto = gson.fromJson(response1.toString(), RenewalAPICallListDTO.class);
显示你的POJO和你用来解析json的任何东西。 – dambros
Gson gson = new Gson(); RenewalAPICallListDTO respDto = gson.fromJson(response1.toString(),RenewalAPICallListDTO.class); –
public class RenewalAPICallListDTO { \t private Map apiCallList; \t public Map getApiCallList(){ \t \t return apiCallList; \t} \t公共无效setApiCallList(地图<整数,JSONCallDto> apiCallList){ \t \t this.apiCallList = apiCallList; \t} \t private String notice; \t \t public String getNotice(){ \t \t return notice; (字符串通知){ \t \t this.notice = notice; \t} \t \t } –