【问题标题】:How to convert JSOn in the form of a String to List<String> in JavaJava中如何将字符串形式的JSOn转换为List<String>
【发布时间】:2020-01-09 07:18:39
【问题描述】:
ObjectMapper mapper = new ObjectMapper();
List<String> stringIds = mapper.readValue(result, new TypeReference<List<String>>(){});

结果 = { “字符串”:[ “ABC”, “xyz” ] }

所以对于输入 { "stringids": [ "abc", "xyz" ] },我希望结果是字符串 abc、xyz 的列表

尝试上述代码时出现此异常:- com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token

【问题讨论】:

标签: java string list


【解决方案1】:

这是因为您不能使用 JSON 库来反序列化损坏的 JSON。

在 JSON 中表示集合的正确方法是 ["abc", "def"] 而不是 {"abd", "def"}

【讨论】:

    猜你喜欢
    • 2022-11-04
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    相关资源
    最近更新 更多