[英]HTML special character decoding
在Android上使用Java我很難轉換幾個html特殊字符。
到目前為止,我已經嘗試過:
String myString = "%A32.00%20per%20month%B3";
Html.fromHtml(myString).toString(); => %A32.00%20per%20month%B3
URLDecoder.decode(myString) => �2.00 per month�
URLDecoder.decode(myString, "UTF-8") => �2.00 per month�
URLDecoder.decode(myString, "ASCII") => �2.00 per month�
org.apache.commons.lang.StringEscapeUtils.unescapeHtml4(myString) => %A32.00%20per%20month%B3
正確的輸出應該是=>每月2.00英鎊³
您的字符串以ISO-8859-1
編碼,因此ASCII和UTF-8不起作用。
String myString = "%A32.00%20per%20month%B3";
URLDecoder.decode(myString, "ISO-8859-1");
// output: £2.00 per month³
public static void main(String[] args) throws UnsupportedEncodingException {
String before = "£2.00 per month³";
String encoded = URLEncoder.encode(before, "UTF-8");
String decoded = URLDecoder.decode(encoded, "UTF-8");
System.out.println(encoded);
System.out.println(decoded);
}
在輸出中我得到:
%C2%A32.00+per+month%C2%B3
£2.00 per month³
你確定%A32.00%20per%20month%B3
是正確的嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.