[英]Android convert ISO-8859-2 to UTF-8
I'm downloading HTML source code of remote page into String variable. 我正在将远程页面的HTML源代码下载到String变量中。 Unfortunetely the page is encoded via iso-8859-2 and contains characters from polish alphabet.
不幸的是,该页面通过iso-8859-2进行编码,并包含波兰字母表中的字符。 How can I convert this string to utf-8, so I can display it's parts in TextView?
如何将此字符串转换为utf-8,以便在TextView中显示它的部分?
Thanks 谢谢
You shouldn't need to "convert" the string at all, if you obey the Content-Encoding
header sent by the web server. 如果遵守Web服务器发送的
Content-Encoding
标头,则根本不需要“转换”字符串。
Right now, you probably ignore that header while reading the response from the server (some BufferedReader-to-StringBuffer/Builder
loop I assume), try this in your download code instead: 现在,您可能在从服务器读取响应时忽略该标头(我假设一些
BufferedReader-to-StringBuffer/Builder
循环),请在下载代码中尝试此操作:
HttpResponse response = ....
String text = EntityUtils.toString(response.getEntity());
EntityUtils will automagically use the content encoding specified by the server. EntityUtils将自动使用服务器指定的内容编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.