//json转换list
public static List<?> jsonToList(String json, Class<?> elementClass)
throws Exception {if (!Util.isBlank(json)) {
if (!"[".equals(json.substring(0, 1))) {
json = "[" + json + "]";
}
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES,
true);
JavaType javaType = mapper.getTypeFactory()
.constructParametricType(ArrayList.class, elementClass);
return mapper.readValue(json, javaType);
}
return null;
}
// json转map
public static Map<String, Object> parseJSON2Map(String jsonStr)
throws Exception {
List<Map<String, Object>> list = (List<Map<String, Object>>) jsonToList(
jsonStr, Map.class);
if (null != list && list.size() > 0) {
return list.get(0);
}
return null;
}