解决网络中的中文乱码问题的方法有很多,下面就列举一些:
Base64:
转码:
//Base64解决中文乱码
public String base64(String content){
try {
content = Base64.encodeToString(content.getBytes("utf-8"), Base64.DEFAULT);
content = URLEncoder.encode(content);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return content;
}
解码:
public String decodeBase64(String content){
try {
byte [] byte_content = Base64.decode(content.getBytes("utf-8"), Base64.DEFAULT);
content = new String(URLDecoder.decode(new String(byte_content)));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return content;
}