【发布时间】:2013-01-24 11:59:20
【问题描述】:
我在我的项目中使用 Zend Framework 1.x。我想为调用者函数创建一个只返回 JSON 字符串的 Web 服务。我尝试使用Zend_Controller_Action 并应用了这些方式:
1.
$this->getResponse()
->setHeader('Content-type', 'text/plain')
->setBody(json_encode($arrResult));
2.
$this->_helper->getHelper('contextSwitch')
->addActionContext('nctpaymenthandler', 'json')
->initContext();
3.
header('Content-type: application/json');
4.
$this->_response->setHeader('Content-type', 'application/json');
5.
echo Zend_Json::encode($arrResult);
exit;
6.
return json_encode($arrResult);
7.
$this->view->_response = $arrResult;
但是当我使用 cURL 来获取结果时,它返回的结果是由一些 HTML 标记包围的 JSON 字符串。然后我尝试使用上述选项用户Zend_Rest_Controller。还是没有成功。
P.S.:以上大部分方法都来自 Stack Overflow 上提出的问题。
【问题讨论】:
标签: php json web-services zend-framework rest