解决方案 我终于明白了:ObjectMapper objectMapper = new ObjectMapper();TypeFactory typeFactory = objectMapper.getTypeFactory();列表someClassList = objectMapper.readValue(jsonString, typeFactory.constructCollectionType(List.class, SomeClass.class));I have a String with the following value:[ { "key1": "value11", "key2": "value12" }, { "key1": "value21", "key2": "value22" }]And the following class:public class SomeClass { private String key1; private String key2; /* ... getters and setters omitted ...*/}And I want to parse it to a List<SomeClass> or a SomeClass[]Which is the simplest way to do it using Jackson ObjectMapper? 解决方案 I finally got it:ObjectMapper objectMapper = new ObjectMapper();TypeFactory typeFactory = objectMapper.getTypeFactory();List<SomeClass> someClassList = objectMapper.readValue(jsonString, typeFactory.constructCollectionType(List.class, SomeClass.class)); 这篇关于如何使用 Jackson 将 JSON 字符串解析为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-20 22:50