前提
因为 fastjson
频频爆出漏洞,所以项目禁止使用 fastjson
,改用 Jackson
和 Gson
方法例子
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public static List<Map<String, Object>> StringToList(String str) {
List<Map<String, Object>> list = new ArrayList<>();
try {
ObjectMapper objectMapper = new ObjectMapper();
CollectionLikeType type = objectMapper.getTypeFactory().constructCollectionLikeType(List.class, Map.class);
list = objectMapper.readValue(str, type);
} catch (JsonProcessingException e) {
e.printStackTrace();
logger.info("数据解析异常,非json标准格式数据!");
}
return list;
}