如何在 Java 中正确解码以下字符串
http%3A//www.google.ru/search%3Fhl%3Dru%26q%3Dla+mer+powder%26btnG%3D%u0420%A0%u0421%u045F%u0420%A0%u0421%u2022%u0420%A0%u0421%u2018%u0420%u040E%u0420%u0453%u0420%A0%u0421%u201D+%u0420%A0%u0420%u2020+Google%26lr%3D%26rlz%3D1I7SKPT_ru
当我使用 URLDecoder.decode() 时出现以下错误
java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u0"
谢谢, 戴夫
最佳答案
根据Wikipedia ,“Unicode 字符存在非标准编码:%uxxxx
,其中 xxxx
是 Unicode 值”。
继续:“任何 RFC 均未指定此行为,并且已被 W3C 拒绝”。
您的 URL 包含此类标记,而 Java URLDecoder 实现不支持这些标记。
关于java - 用Java解码字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5408538/