JSON反序列化投掷例外 - 无法反序列化的java.util.ArrayList实例出来START_OBJECT令牌 [英] JSON deserialization throwing exception - Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

查看:35021
本文介绍了JSON反序列化投掷例外 - 无法反序列化的java.util.ArrayList实例出来START_OBJECT令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的JSON响应,

The below is my JSON response,

产生的原因:com.fasterxml.jackson.databind.JsonMappingException:无法反序列化的java.util.ArrayList实例出来START_OBJECT令牌
 在[来源:java.io.PushbackInputStream@bce1d9;行:1,列:556](通过参考链:com.totalHours [数据] - > com.totalHours [hourly_totals])

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.PushbackInputStream@bce1d9; line: 1, column: 556] (through reference chain: com.totalHours["data"]->com.totalHours["hourly_totals"])

 "totalHours": 
  {
     "hourly_totals": 
     {
        "2013112101":
        {
           "distance": 1324,
           "calories": 90.0120018125,
           "steps": 1603,
           "active_time": 793,
           "inactive_time": 220,
           "longest_active_time": 302,
           "longest_idle_time": 780
        },
        "2013112101":
        {
           "distance": 626,
           "calories": 47.0120018125,
           "steps": 455,
           "active_time": 246,
           "inactive_time": 260,
           "longest_active_time": 203,
           "longest_idle_time": 650
        },
        ... more hours ...
     }  

我已经花了POJO类类似下面,我得到一个例外,当我尝试反序列化的json数据。

I have took a pojo class like below, I am getting an exception when I try to deserialize the my json data.

public class totalHours{
private List<String> hourly_totals;
}

不过,我不知道是否采取列表,因为在响应没有数组。会有什么其他选择尝试了。

But, I don't know whether to take a List because there is no array in response. What will be the other options to try out for.

推荐答案

hourly_totals 是psented作为一个字符串到另一个对象一个小时再$ P $的对象,以地图&LT;弦乐,T&GT; ,其中T是一个POJO类,再presenting数据一小时,看起来像一个自然的选择。

hourly_totals is an object from an hour represented as a string to another object, to Map<String,T> , where T is a POJO class representing the data for one hour, would look like a natural choice.

这篇关于JSON反序列化投掷例外 - 无法反序列化的java.util.ArrayList实例出来START_OBJECT令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆