json_encode网址失败

Ste*_*hry 2 php json zend-framework

有没有办法绕过这个bug

echo json_encode(array('url'=>'/foo/bar'));
{"url":"\/foo\/bar"}
Run Code Online (Sandbox Code Playgroud)

我使用Zend_Json和Zend_Json_Expr,所以我甚至可以在我的js对象中获得回调函数 - 但是我无法获得一个可用格式的url!

echo Zend_Json::encode(array(
                         'url'=>new Zend_Json_Expr('/foo/bar'),
                       ), false,
                       array(
                         'enableJsonExprFinder' => true),
                       ));
Run Code Online (Sandbox Code Playgroud)

生产:

{"url":/foo/bar}
Run Code Online (Sandbox Code Playgroud)

这显然也不对..

无论如何得到:

{"url":"/foo/bar"}
Run Code Online (Sandbox Code Playgroud)

没有做任何荒谬的事情,比如在将它发送到stdio之前找到一种方法将其重新出发?

Jor*_*ore 7

{"url":"\/foo\/bar"}实际上是"/ foo/bar"的完全有效和正确的JSON.尝试使用json_decode()或解码该值Zend_Json::decode(),它应该正确输出您的原始URL.