0
URLDecoder.decode抛出UnsupportedEncodingException
。URLDecoder.decode(encodedString,“UTF-8”)替代方案
是否有任何其他方式来实现解码,而不处理此异常?
public static void main(String[] args) throws UnsupportedEncodingException {
String encodedString = "Testing some character I want to claim %C2%A3300.00 I want to claim %24400.00 I want to claim %E2%82%AC500.00";
System.out.println(URLDecoder.decode(encodedString, "UTF-8"));
byte[] bytes = encodedString.getBytes("UTF-8");
String s2 = new String(bytes, "UTF-8");
System.out.println(s2); //doesnt work
String decoded = new String(encodedString.getBytes("ISO-8859-1"));
System.out.println(decoded); //doesnt work
}
输出:
Testing some character I want to claim £300.00 I want to claim $400.00 I want to claim €500.00
Testing some character I want to claim %C2%A3300.00 I want to claim %24400.00 I want to claim %E2%82%AC500.00
Testing some character I want to claim %C2%A3300.00 I want to claim %24400.00 I want to claim %E2%82%AC500.00
为什么你期望将**编码**字符串的字节转换为新字符串来解码它?没有办法处理异常 – XtremeBaumer
你的第一行声称'URLDecoder.decode'抛出'UnsupportedEncodingException' - 但是你提供的代码和输出表明它没有。这是什么? –
URLDecoder.decode(encodedString,“UTF-8”) - 这个例外。 –