Java中将Map转String,String转Map

暴力的直接Map对象toString()存,后面取出是就是用再转换为Map

String转Map:

JSONObject jsonobject = JSONObject.fromObject(str);
rMap = (Map<String, Object>) jsonobject;

但很多时候并不能直接将Map对象的toString()
而是应该转换为JsonObject后再调用toString()后存入就正常了

Map<String,Object> map=new HashMap<>();
map.put("fff","fff");
System.out.println(map.toString());

JSONObject jsonObject=JSONObject.fromObject(map);
System.out.println(jsonObject.toString());
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章