标签:blank util shm key else nbsp tar with from
1 //json字符串转换为MAP 2 public static Map jsonStrToMap(String s) { 3 Map map = new HashMap(); 4 //注意这里JSONObject引入的是net.sf.json 5 net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(s); 6 Iterator keys = json.keys(); 7 while (keys.hasNext()) { 8 String key = (String) keys.next(); 9 String value = json.get(key).toString(); 10 if (value.startsWith("{") && value.endsWith("}")) { 11 map.put(key, jsonStrToMap(value)); 12 } else { 13 map.put(key, value); 14 } 15 16 } 17 return map; 18 } 19 20 // 将jsonArray字符串转换成List集合 21 public static List jsonToList(String json, Class beanClass) { 22 if (!StringUtils.isBlank(json)) { 23 //这里的JSONObject引入的是 com.alibaba.fastjson.JSONObject; 24 return JSONObject.parseArray(json, beanClass); 25 } else { 26 return null; 27 } 28 } 29 30 //List集合转换为json 31 public static JSON listToJson(List list) { 32 JSON json=(JSON) JSON.toJSON(list); 33 return json; 34 }
JAVA中json转Map,jsonArray转List集合,List集合转json
标签:blank util shm key else nbsp tar with from
原文地址:https://www.cnblogs.com/xiaoyue1606bj/p/11577240.html