【发布时间】:2015-01-07 19:27:03
【问题描述】:
我需要对地图值进行编码并重新解码。下面的代码不解码值。
byte[] bytes = "This,is,test".getBytes("UTF-8");
Map<String, Object> map = new HashMap<String,Object>();
map.put("description",bytes);
String s1= map.toString();
String s2[]=s1.substring(1,s1.length()-1).split("=");
String string1 = new String(s2[1].getBytes(), "UTF-8");
System.out.println(string1);
【问题讨论】:
-
呃,你为什么要这么做?
-
尝试将
System.out.println(s1)添加到您的程序中,看看它会打印什么...您希望map.toString()返回什么?如果地图中有多个条目,您希望它会做什么? -
你想从你的地图制作 json 字符串,反之亦然吗?
标签: java dictionary utf-8 decode encode