Zend $this->_helper->json 返回数组而不是 JSON
我们正在使用 ZEND Framework 开发 API。这是一个示例响应,
$this->getResponse()
->setHttpResponseCode(200)
->appendBody($this->_helper->json($client->toArray()));
我想象 $this->_helper->json 会返回一个 JSON 字符串,但它返回一个数组(在开发环境中)。
我现在可以使用临时服务器,并且相同的代码返回 JSON 字符串。
开发环境当前是不同的 PHP 版本(dev 是 5.3.1,staging 是 5.3.3)这是原因吗?这些不同版本的 JSON 编码是否不同?知道为什么会发生这种情况吗?
We are developing an API with the ZEND Framework. Here is an example response
$this->getResponse()
->setHttpResponseCode(200)
->appendBody($this->_helper->json($client->toArray()));
I imagined $this->_helper->json would return a JSON string but its returning an array (in the dev environment).
I now have the staging server to play with and the very same code is returning JSON strings.
The dev environment is currently a different PHP version (dev is 5.3.1, staging is 5.3.3) is this the cause? Do these different versions encode JSON differently? Any idea why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,明智的做法是将嵌套函数调用分解为单独的调用,并 var_dump 每个结果以验证内部内容是否按预期工作:
In this case it would have also been wise to break your nested function calls into separate calls and var_dump each result to verify the inner contents is working as you expected: