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());
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章