[英]How to convert JSOn in the form of a String to List<String> in Java
ObjectMapper mapper = new ObjectMapper();
List<String> stringIds = mapper.readValue(result, new TypeReference<List<String>>(){});
结果= {“stringids”:[“abc”,“xyz”]}
所以对于 Input { "stringids": [ "abc", "xyz" ] }
,我希望结果是字符串 abc, xyz 的列表
尝试上述代码时出现此异常:- com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
那是因为您不能使用 JSON 库来反序列化损坏的 JSON。
在 JSON 中表示集合的正确方法是["abc", "def"]
而不是{"abd", "def"}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.