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("-")
}
}
}
posted @ 2018-01-10 16:46  龙卷风清扬  阅读(482)  评论(0编辑  收藏  举报