如何使用java pojo類反序列化下面的json響應。無法反序列化JSON響應
JSON響應
"details":
{
"distance": 14745,
"km": 14.745,
"steps": 16804,
"active_time": 11927,
"longest_active": 2516,
"inactive_time": 32760,
"longest_idle": 27180,
"calories": 1760.30480012,
"bmr_day": 1697.47946931,
"bmr": 1697.47946931,
"bg_calories": 1099.9439497,
"wo_calories": 388.506116077,
"wo_time": 11484,
"wo_active_time": 3902,
"wo_count": 2,
"wo_longest": 2516,
"tz": "America/Los Angeles",
"tzs":
[
[1384963500, "America/Phoenix"],
[1385055720, "America/Los_Angeles"]
]
}
我已經寫了下面的POJO漁獲反序列化JSON響應。
Response.java
public class Response {
private Distance distance;
}
Distance.java
public class Distance{ private int distance;
private double km;
private int steps;
private int active_time;
private int longest_active;
private int inactive_time;
private int longest_idle;
private int calories;
private int bmr_day;
private int bmr;
private int bg_calories;
private int wo_calories;
private int wo_time;
private int wo_active_time;
private int wo_count;
private int wo_longest;
private int sunrise;
private int sunset;
private String tz;
private String[] tzs;
private String hourly_totals;
}
我得到了下面的異常,
Can not deserialize instance of java.lang.String out of START_ARRAY token
atSource: [email protected];(through reference chain: Details["tzs"]);
nested exception is com.fasterxml.jackson.databind.JsonMappingException:
Can not deserialize instance of java.lang.String out of START_ARRAY token
如何克服這一點。
嘗試改變爲字符串[ ] tzs as List
你不需要類TimeZone來匹配那部分JSON嗎? –
您的JSON響應中的'tzs'不是字符串數組(而不是您的'Response'類),而是一個字符串數組數組。 –