java json转map

1. 单 示例:

String str = "{"C":"1006","N":"玫瑰"}"

转:

Map<String, String> maps = new HashMap<>()

def xtr = objectMapper.readValue(str, Map.class)

2. 多 示例: 

def flistjson= "[{"C":"1006","N":"牡丹"},{"C":"1007","N":"葡萄"},{"C":"1008","N":"玫瑰"}"

if (deptlistjson){

    JavaType javaType = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, Map.class)
ArrayList<Map<String,String>> flowlist=objectMapper.readValue(flistjson, javaType) as ArrayList<Map<String,String>>;
for (def f : flistjson){
String code=f("C")
if (code.contains("-")){
String[] codes=code.split("-")
}
}
}
原文地址:https://www.cnblogs.com/pokay/p/8259448.html