Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Cakephp呈现JSON_Php_Json_Cakephp - Fatal编程技术网

用Cakephp呈现JSON

用Cakephp呈现JSON,php,json,cakephp,Php,Json,Cakephp,我试图使用Cakephp 2.1从外部表单返回Json对象。我有我所有的数据,我已经查看了回复,问题是我在JSON之前收到了大量的错误文本 下面是我用来打印json的代码: if (!$validationPassed) { if ($ExternalRequest) { if ($shouldEchoErrors){ Configure::write('debug',0); // Disabled so theoretically it c

我试图使用Cakephp 2.1从外部表单返回Json对象。我有我所有的数据,我已经查看了回复,问题是我在JSON之前收到了大量的错误文本

下面是我用来打印json的代码:

if (!$validationPassed) {

    if ($ExternalRequest) {

        if ($shouldEchoErrors){

            Configure::write('debug',0); // Disabled so theoretically it can't even print errors
            $this->RequestHandler->setContent('json', 'application/json' );
            $json = json_encode($this->Customer->validationErrors);
            echo $json;
            $this->autoRender = false ;
        }

它打印的JSON是正确的,{Email:[EmailUnique]}。然而,在此之前,我得到了一个巨大的预格式化错误消息,堆栈跟踪和所有内容

这是一个愚蠢的时刻,但如果其他人发现这个问题,答案是:

在代码的前面有一个错误,当debug打开时,cake将立即打印它。这将被包装到json输出中


具体的错误与这个问题无关,它只是在视图中

你希望我们猜出错误,对吗?