/**
* 字符串格式化
*/
public static List<JSONObject> getList(String data){
ObjectMapper mapper = new ObjectMapper();
JavaType javaType = getCollectionType(ArrayList.class, JSONObject.class);
List<JSONObject> list = null;
try {
list = mapper.readValue(data,javaType);
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
return new ObjectMapper().getTypeFactory().constructParametricType(collectionClass, elementClasses);
}
String转换List<JSONObject>
最新推荐文章于 2024-02-28 09:17:43 发布
本文介绍了一种将JSON格式的字符串转换为Java中List<JSONObject>的方法。使用了ObjectMapper来解析JSON字符串,并通过自定义的getCollectionType方法指定了泛型类型。
8072





