本文共 582 字,大约阅读时间需要 1 分钟。
知道Jackson可以做这个,只是不经常用到。用到了,查到了……
方法一:
String jsonString="[{'id':'1'},{'id':'2'}]";ObjectMapper mapper = new ObjectMapper();JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, Bean.class);//如果是Map类型 mapper.getTypeFactory().constructParametricType(HashMap.class,String.class, Bean.class);Listlst = (List )mapper.readValue(jsonString, javaType);
方法二:
String jsonString="[{'id':'1'},{'id':'2'}]";ObjectMapper mapper = new ObjectMapper();ListbeanList = mapper.readValue(jsonString, new TypeReference
>() {});
转载地址:http://qrgmb.baihongyu.com/