String to map in java, map to String, mutual conversion between map and String

String to map:

Map map_new = new Gson().fromJson(s, map.getClass());//Need to import jar package

but! Still can’t convert complex ones, such as map.put(“getAll=toMe”,”one”) , it will go wrong

referenced jar


code to test

public static void main(String[] args) {
    Map map = new HashMap<String,String>();
    String s = map.toString();
    Map map_new = new Gson().fromJson(s, map.getClass());

result of running

Leave a Comment

Your email address will not be published. Required fields are marked *