public class URLDecoder extends Object
application/x-www-form-urlencoded MIME格式解码字符串的静态方法。
转换过程与URLEncoder类使用的转换过程相反。 假设编码字符串中的所有字符都是以下之一:“ a ”至“ z ”,“ A ”至“ Z ”,“ 0 ”至“ 9 ”和“ - ”,“ _ ”,“ . “和” * “。 字符“ % ”被允许,但被解释为特殊转义序列的开始。
在转换中应用以下规则:
a ”至“ z ”,“ A ”至“ Z ”和“ 0 ”至“ 9 ”保持不变。 . ”,“ - ”,“ * ”和“ _ ”保持不变。 + ”被转换为空格字符“”。 %xy ”的序列将被视为表示一个字节,其中xy是8位的两位十六进制表示。 然后,连续包含这些字节序列中的一个或多个的所有子字符串将被编码将导致这些连续字节的字符替换。 可以指定用于解码这些字符的编码方案,或者如果未指定,则将使用平台的默认编码。 这种解码器可以处理非法字符串的两种可能方式。 它可以单独留下非法字符,也可以抛出一个IllegalArgumentException 。 解码器采用的方法是实现。
| Constructor and Description |
|---|
URLDecoder() |
@Deprecated public static String decode(String s)
x-www-form-urlencoded字符串。
平台的默认编码用于确定由“ %xy ”形式的任何连续序列表示的%xy 。
s - 要解码的
String
String
public static String decode(String s, String enc) throws UnsupportedEncodingException
application/x-www-form-urlencoded字符串。
所提供的编码用于确定由“ %xy ”形式的任何连续序列表示哪些字符。
注意: World Wide Web Consortium Recommendation规定应使用UTF-8。 不这样做可能会引起不兼容。
s - 要解码的
String
enc -支持的名称
character encoding 。
String
UnsupportedEncodingException - 如果需要查询字符编码,但不支持命名字符编码
URLEncoder.encode(java.lang.String, java.lang.String)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.