我在对HTTP REST响应中的丹麦字母进行编码时遇到了问题。
当我调用REST服务时,我得到了"bev�ge",它必须是“beváge”,Chrome浏览器对其进行编码,并给出预期的字母“beváge”,但是当我读到来自Java API的响应时,我得到了"bev�ge“,有人能帮我解决这个问题吗,那就太棒了。
提前感谢
发布于 2017-07-25 13:58:31
您的编码似乎不匹配
考虑一下
String str = "bevæge";
byte[] b = str.getBytes();
try {
System.out.println(new String (b, "US-ASCII"));
System.out.println(new String (b, "UTF8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}输出将是
bev��ge
bevæge发布于 2017-07-25 14:11:41
看起来像是,如果字符串作为ISO8859-1传输
请在下面进行尝试:
String str = "bevæge";
byte[] b = str.getBytes();
try {
System.out.println(new String (b, "ISO8859-1"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}将输出
beváge
发布于 2017-07-25 14:37:24
在您的HttpClient中,尝试添加以下标题: Accept-charset: UTF-8
https://stackoverflow.com/questions/45294884
复制相似问题