2009-12-03 82 views
2

是否有任何解决方法this bugjson_encode url失败

echo json_encode(array('url'=>'/foo/bar')); 
{"url":"\/foo\/bar"} 

我用Zend_Json and Zend_Json_Expr所以我可以让我的JS对象中甚至回调函数 - 但我不能让一个URL可用格式出来!

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

生产:

{"url":/foo/bar} 

这显然是不正确的或者..

反正是有得到:

{"url":"/foo/bar"} 

,而无需做任何事情荒谬喜欢找在将它发送到stdio之前将它重新排列的一种方法?

回答

7

{"url":"\/foo\/bar"}对于“/ foo/bar”实际上是完全有效且正确的JSON。尝试使用json_decode()Zend_Json::decode()解码该值,并且它应该正确输出原始网址。

+0

是的,这是正确的JSON,并进一步调查window.location ='http:\/\/www.google.com \ /';似乎工作..看起来像它是我使用的插件中的错误:-p – 2009-12-03 20:31:56

+0

而且,使用_Expr本质上只是告诉编码器不要将它放在引号中或转义值 - 就像Zend_Db_Expr。 – Justin 2009-12-04 00:21:39