直接上代码
py
data = {
'name' : 'Connor'
}
print(json.dumps(data))
print(b64encode(bytes(json.dumps(data))))
结果
{"name": "Connor"}
eyJuYW1lIjogIkNvbm5vciJ9
java
BASE64Encoder encoder = new BASE64Encoder();
Map<String,String> ret = new HashMap<>();
ret.put("name","Connor");
String s = JSON.toJSONString(ret);
out.println(s);
try {
out.println(encoder.encode(s.getBytes("UTF-8")));
} catch( UnsupportedEncodingException e ) {
e.printStackTrace();
}
结果
{"name":"Connor"}
eyJuYW1lIjoiQ29ubm9yIn0=
求高人指点。。。不胜感激!!!
py的多了一个空格