简体   繁体   English

HTML特殊字符解码

[英]HTML special character decoding

Using Java on Android I'm struggling to convert a couple of html special characters. 在Android上使用Java我很难转换几个html特殊字符。

So far I've tried: 到目前为止,我已经尝试过:

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

The correct output should be => £2.00 per month³ 正确的输出应该是=>每月2.00英镑³

Your string is encoded in ISO-8859-1 , so ASCII and UTF-8 won't work. 您的字符串以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);
}

In output I get: 在输出中我得到:

%C2%A32.00+per+month%C2%B3
£2.00 per month³

Are you sure that %A32.00%20per%20month%B3 is correct? 你确定%A32.00%20per%20month%B3是正确的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM