1、JSON串转换 成 List<T> 方法
String jsonString=[{},{}];
JavaType javaTypes = getCollectionType(List.class, T.class);
List<T> lists= mapper.readValue(jsonString, javaTypes);
public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
return mapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
}
2、从json中转换某个List属性
jsonString={id:0,list:[]};
JSONObject jsonStr = new JSONObject(jsonString);
JSONArray formName = (JSONArray) jsonStr.get("list");