我有以下JSON字符串,用PHP 5.2 json_encode()编码:
{"foo":"\\."}
Run Code Online (Sandbox Code Playgroud)
此JSON字符串有效.你可以在http://www.jsonlint.com/上查看.
但是原生JSON.parse()方法(Chrome,Firefox)在解析时会抛出以下错误:
SyntaxError: Unexpected token ILLEGAL
Run Code Online (Sandbox Code Playgroud)
有谁知道,为什么我不能解析逃脱的正则表达式元字符?
这个例子有效:
{"foo":"\\bar"}
Run Code Online (Sandbox Code Playgroud)
但是这个也失败了:
{"foo":"\\?"}
Run Code Online (Sandbox Code Playgroud)
BTW:\.只是一个简单的测试正则表达式,我想通过javascript的RegExp对象运行.
感谢您的支持,
Dyvor