嗨,我有一个代码,在cakephp中返回一个JSON响应,它在localhost中完美工作,但在生产中,它提供了不正确的JSON响应解析。 例如这里是我的动作代码Json数组返回生产与cakephp
public function deletepic(){
///configuration de l'ajax
$this->autoRender = false;
$this->request->allowMethod(array('ajax'));
$message = array('key'=>'hello');
if($this->request->is(array('ajax'))){
$picid = $this->request->data['id'];
$picname = $this->request->data['attachmentname'];
if($this->Profile->deleteAll(array('Pic.id'=>$picid,'Pic.attachment'=>$picname),false)){
$message = array('info'=>'good');
}
else{
$message = array('info'=>'bad');
}
}
$this->response->type = 'json';
return json_encode($message, JSON_PRETTY_PRINT);
}
,并返回给我下面的JSON响应:
{
"info"
我不知道是什么导致这个probleme,因为相同的代码工作在本地机器上
它可能实际上有适当的细节。您的实时服务器系统可能会在日志中截断打印新行。尝试打印'json_encode($ message)' –
你是什么意思的托盘打印json_encode($ message)??我应该手动构建json而不是使用json_encode? – user1655410
我的意思是你尝试返回没有'JSON_PRETTY_PRINT',就像'return json_encode($ message)' –