List转JSON,Map转JSON,JSON转List、Map方法总结:

List、Map、JSON、String 互转方法总结:

先叙述一下没有jar包时候的困惑;

不行就自己写一个吧!

public static List parseStringToListMap(String str1) {
        if (StringUtil.isBlank(str1)){
            return new ArrayList();
        }
        String[] oraginStr = str1.split("}, \\{");
        List resultList = Arrays.asList(oraginStr);
        if(oraginStr.length<=1){
            return resultList;
        }
        List listRest = new ArrayList();
        for (int j = 0; j < resultList.size(); j++) {
            String checkIndex = String.valueOf(resultList.get(j));
            checkIndex = checkIndex.replaceAll("]", "").replaceAll("\\[", "").replaceAll("\\{", "").replaceAll("}", "");
            String str2[] = checkIndex.split(",");
            Map mapIn = new HashMap();
            for (int i = 0; i < str2.length; i++) {
                String str3 = str2[i];
                if (StringUtil.isBlank(str3)) {
                    continue;
                }
                String str4[] = str3.split("=");
                if (2 == str4.length) {
                    mapIn.put(str4[0].trim(), str4[1].trim());
                } else if (1 == str4.length) {
                    mapIn.put(str4[0].trim(), "");
                } else {
                    continue;
                }
            }
            listRest.add(mapIn);
        }
        return listRest;
    }








猜你喜欢

转载自blog.csdn.net/select_bin/article/details/80830664