String转map:
Map map_new = new Gson().fromJson(s, map.getClass());//需要引入jar包
不过!还是不能转换复杂的,比如 map.put("getAll=toMe" , "one" ) ,就会出错的哦
引用的jar
<!-- 配置gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
测试的代码
public static void main(String[] args) {
Map map = new HashMap<String,String>();
map.put("a","a111");
map.put("a1","a111");
map.put("a2","a111");
System.out.println("原:\t"+map);
String s = map.toString();
System.out.println("中:\t"+s);
Map map_new = new Gson().fromJson(s, map.getClass());
System.out.println("后:\t"+map_new);
}
运行的结果