在 GWT 中,我尝试通过 JSON 提供正则表达式作为输入,并尝试再次读回它。但是在从 JSON 读回值时,我在输入过程中给出的\字符丢失了。
String input = "{\"digit\":\"(\d*)\"}";
JSONValue parse = JSONParser.parseLeneient(input);
JSONObject jsonObj = parse.isObject();
if(jsonObj!=null) {
for(String key:jsonObj.keySet()) {
System.out.prinltn(jsonObj.get(key).toString();
}
}
我得到的输出是
(d*)
如何使\字符也出现在我的输出中?
最佳答案
The representation of strings is similar to conventions used in the C family of programming languages. A string begins and ends with quotation marks. All Unicode characters may be placed within the quotation marks except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).
反斜线是\
。 因此您不能将 \
单独放置在 JSON 字符串中。
由于您的解析很宽松,因此它只是忽略 \
,因为 \d
is not a valid escape sequence.
基本上是 JSON
{
"digit": "(\d*)"
}
不是valid .
关于java - GWT JSON 解析正在删除\字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21771982/