Zend响应应用程序/ json utf-8

Whi*_*her 5 php json zend-framework

通常在xhr动作中我使用此代码

$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$response = $this->getResponse();
$response->setHeader('Content-type', 'application/json', true);
return $response->setBody(Zend_Json::encode($data));
Run Code Online (Sandbox Code Playgroud)

我想知道它是否需要像这样的utf-8编码

$response->setHeader('Content-type', 'application/json;charset=UTF-8', true);
Run Code Online (Sandbox Code Playgroud)

dat*_*age 12

这样做是好习惯.如果不这样做,您可能看不到任何问题.这取决于您发送的数据类型.

有一个更短的方法来做你正在做的事情(禁用布局并设置正确的标题):

 $this->_helper->json->sendJson($data);
Run Code Online (Sandbox Code Playgroud)