【发布时间】:2012-09-20 08:15:48
【问题描述】:
当我从网页阅读一些文本时,我在 TextView 中显示 unicode 字符时遇到一些问题。
我正在使用以下代码检索网页内容:
try {
HttpGet request = new HttpGet();
request.addHeader("User-Agent", USER_AGENT);
request.setURI(new URI(wwwlink));
try {
response4 = httpClient.execute(request);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (URISyntaxException e) {e.printStackTrace();}
try {
in2 = null;
String UTF8 = "UTF-8";
in2 = new BufferedReader (new InputStreamReader(response4.getEntity().getContent(),UTF8));
} catch (IllegalStateException e) {Log.i(tag,e.toString());
} catch (IOException e) {Log.i(tag,e.toString());}
我正在阅读的页面有这个 HTML 标题标签:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
现在的问题是:我阅读了行和一些我需要的文本包含这样的 unicode 字符:
20 \u00b0C (20 degree symbol C )
我正在尝试将其转换并在 TextView 中显示为度数符号。
以下工作正常
textview.settext("\u00b0");
但是当我这样做时,该行包含 unicode 字符:
line = in2.readln;
textview.settext(line);
TextView 将显示 f.e.: some text \u00b0 some text
我已经用模拟器和手机检查了一切。
【问题讨论】:
-
我很确定这是重复的。在 SO 上搜索。
-
找不到它......就像在 python string.decode -> 我认为同样的问题。
标签: java android string unicode textview