解码包含百分比(%)的字符串

use*_*996 5 java

我正在尝试解码String包含(%)百分比的,它抛出异常

Exception:URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "%&"
Run Code Online (Sandbox Code Playgroud)

我的代码:

public class DecodeCbcMsg {

    public static void main(String[] args) throws UnsupportedEncodingException 
    {
        String msg="Hello%%&&$$";
        String strTMsg = URLDecoder.decode(msg,"UTF-8");
        System.out.println(strTMsg);
    }
Run Code Online (Sandbox Code Playgroud)

vik*_*eve 2

看起来你的字符串编码不正确......

也许您应该首先确保它被正确编码?

例如,编码的字符表示%%25...

所以请尝试解码Hello%25%25%26%26%24%24,看看你会得到什么:)