我有一個字符串,它通過一個XML來,它是德文文本。德國特定的字符是通過UTF-8格式編碼的。在顯示字符串之前,我需要解碼它。解碼字符串編碼utf-8格式在android
我曾嘗試以下:
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(
new ByteArrayInputStream(nodevalue.getBytes()), "UTF8"));
event.attributes.put("title", in.readLine());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我也試過這樣:
try {
event.attributes.put("title", URLDecoder.decode(nodevalue, "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
他們都不是工作。如何解碼德文字符串
謝謝您提前。
UDPDATE:
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
super.characters(ch, start, length);
if (nodename != null) {
String nodevalue = String.copyValueOf(ch, 0, length);
if (nodename.equals("startdat")) {
if (event.attributes.get("eventid").equals("187")) {
}
}
if (nodename.equals("startscreen")) {
imageaddress = nodevalue;
}
else {
if (nodename.equals("title")) {
// try {
// BufferedReader in = new BufferedReader(
// new InputStreamReader(
// new ByteArrayInputStream(nodevalue.getBytes()), "UTF8"));
// event.attributes.put("title", in.readLine());
// } catch (UnsupportedEncodingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// try {
// event.attributes.put("title",
// URLDecoder.decode(nodevalue, "UTF-8"));
// } catch (UnsupportedEncodingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
event.attributes.put("title", StringEscapeUtils
.unescapeHtml(new String(ch, start, length).trim()));
} else
event.attributes.put(nodename, nodevalue);
}
}
}
我無法在需要時找到此問題解答。因此,我現在已經複製了它,我希望這將快速彈出下一次 – Jayy 2013-04-30 13:51:27