为什么
new URI(
null,
null,
"/monitor/123456/data",
"filterParams=[{\"id\":12,\"type\":\"dimension\"}]",
null).getQuery()
返回
filterParams = [%7B%22id%22:12,%22type%22:%22dimension%22%7D]
而不是
“filterParams = [{\” ID \ “:12,\” 类型\ “:\” 维度\ “}]”
根据URI#getQuery()
文档
此方法返回的字符串等于
#getRawQuery()
方法返回的字符串,但所有转义的八位字节序列都被解码。
这是JDK错误还是我在这里缺少一些理解?
答案 0 :(得分:0)
根据私有方法URI.decode上面的评论,它不是一个bug而是一个特征:)。
/*
Evaluates all escapes in s, applying UTF-8 decoding if needed. Assumes
that escapes are well-formed syntactically, i.e., of the form %XX. If a
sequence of escaped octets is not valid UTF-8 then the erroneous octets
are replaced with '\uFFFD'.
Exception: any "%" found between "[]" is left alone. It is an IPv6 literal with a scope_id
*/
private static String decode(String s) {...}