我有以下結構的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 } –