直接上代码:
public static void main(String[] args) {
//map 的类型:
Map<String, List<Map<String, String>>> map = new HashMap<String, List<Map<String, String>>>();
List<Map<String,String>> list = new ArrayList<Map<String, String>>();
Map<String,String> map1 = new HashMap<String, String>();
map1.put("l1","hello");
map1.put("l2","world");
Map<String,String> map2 = new HashMap<String, String>();
map2.put("l3","hello3");
map2.put("l4","world4");
list.add(map1);
list.add(map2);
map.put("a",list);
map.put("b",list);
String mapString = map.toString();
Map<String, List<Map<String, String>>> mapConveter = new HashMap<String, List<Map<String, String>>>();
String pairs[] = mapString.split("]");
for (String pair : pairs) {
List<Map<String,String>> list1= new ArrayList<Map<String,String>>();
String[] split = pair.replace("[", "").split("=");
String[] split1 = pair.split("\\[");
for (int i=1;i<split1.length;i++){
String[] split2 = split1[i].split(",");
for (int j=0;j<split2.length;j++){
Map<String,String> mapSingle = new HashMap<String, String>();
String[] split3 = split2[j].replace("}", "").replace("{", "").split(",");
for (int m=0;m<split3.length;m++){
String[] split4 = split3[m].split("=");
mapSingle.put(split4[0],split4[1]);
}
list1.add(mapSingle);
}
}
mapConveter.put(split[0].replace("{",""),list1);
}
System.out.println("successfully");
}