【问题标题】:Can not deserialize instance of contactupload.User out of START_ARRAY token无法反序列化 contactupload.User 的实例超出 START_ARRAY 令牌
【发布时间】:2013-12-19 11:02:01
【问题描述】:

我正在使用 jackson api 解析 json 响应,我遇到了这个异常,请帮助我 我是杰克逊解析的新手。

json 响应:

[{"0":"96859","userid":"96859","1":"fshdh","phoneid":"fshdh","2":"","imageid":""},{"0":"67656656","userid":"67656656","1":"bdndjj","phoneid":"bdndjj","2":"","imageid":""},{"0":"6469895","userid":"6469895","1":"vzbdjn","phoneid":"vzbdjn","2":"","imageid":""},{"0":"6865665","userid":"6865665","1":"hdhdhh","phoneid":"hdhdhh","2":"","imageid":""}]

杰克逊解析:

private User user;
    ObjectMapper mapper=new ObjectMapper();
    user=mapper.readValue(response, User.class);

【问题讨论】:

  • 显示您的用户类别。它是一个列表。所以你必须使用集合的类型引用来反序列化。

标签: android json jackson


【解决方案1】:

您需要更改它以读取用户数组:

ObjectMapper mapper = new ObjectMapper();
User[] users = mapper.readValue(response, User[].class);

【讨论】:

    猜你喜欢
    • 2014-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-20
    • 2017-10-10
    • 2020-07-14
    • 1970-01-01
    • 2020-09-23
    相关资源
    最近更新 更多