我在
PHP中使用json_encode来编码一个URL
$json_string = array ('myUrl'=> 'http://example.com'); echo json_encode ($json_string);
{"myUrl":"http:\/\/example.com"}
而不是
{"myUrl":"http://example.com"}
根据
http://www.json.org/,一个人应该逃避这个角色,虽然JavaScript并不是绝对必要的:
还可以在PHP.net上阅读这个related bug report,进行简短的讨论.
参见RFC中的2.5:
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).Any character may be escaped.
所以它听起来不像是需要被转义,但它可以,网站(和RFC中的一个文本图)说明它被转义.