【发布时间】:2014-04-24 04:14:27
【问题描述】:
我正在从网站获取 html 文本。该站点返回如下图所示的字符。我试图从站点找到字符集,它找到了<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
它在文本视图中设置后显示设备上的输出,如:
我尝试了一些编码,但不影响文本,如下所示:
final Charset windowsCharset = Charset.forName("windows-1252");
final Charset utfCharset = Charset.forName("UTF-8");
final CharBuffer windowsEncoded = windowsCharset.decode(ByteBuffer
.wrap(ne.scrape_detail_article_text.getBytes()));
final byte[] utfEncoded = utfCharset.encode(windowsEncoded).array();
// System.out.println(new String(utfEncoded, utfCharset.displayName()));
String s = "" ;
try {
// String s = new String(utfEncoded, utfCharset.displayName());
//String s = new String(texttoencoding.getBytes("windows-1252"),"UTF-8");
s = URLEncoder.encode(texttoencoding, "windows-1252");
Log.e("LOG", "Encoded >> " + s);
} catch (UnsupportedEncodingException e) {
Log.e("utf8", "conversion", e);
}
TextviewToset.setText(Html.fromHtml(texttoencoding);
TextviewToset.setMovementMethod(LinkMovementMethod.getInstance());
请帮帮我,我怎样才能将此文本编码为UTF-8 并显示在文本视图中?
提前致谢
【问题讨论】:
标签: android text utf-8 character-encoding