public function json($data, $jsonp = false)
    {
        $options = 0;
        defined('JSON_UNESCAPED_UNICODE') && $options = JSON_UNESCAPED_UNICODE;
        $content = json_encode($data, $options);

        if ($jsonp && preg_match('/^[$A-Z_][0-9A-Z_$.]*$/i', $this->request['callback']) === 1) {
            $this->setHeader('Content-Type', 'application/javascript');
            $content = $this->request['callback'] . '(' . $content . ')';
        } else {
            $this->setHeader('Content-Type', 'application/json');
        }

        return $this->setContent($content);
    }
public function json($data, $jsonp = false)
    {
        $options = 0;
        defined('JSON_UNESCAPED_UNICODE') && $options = JSON_UNESCAPED_UNICODE;
        $content = json_encode($data, $options);

        if ($jsonp && preg_match('/^[$A-Z_][0-9A-Z_$.]*$/i', $this->request['callback']) === 1) {
            $this->setHeader('Content-Type', 'application/javascript');
            $content = $this->request['callback'] . '(' . $content . ')';
        } else {
            $this->setHeader('Content-Type', 'application/json');
        }

        return $this->setContent($content);
    }
public function json ( $ data , $ jsonp = false ) { $ options = 0 ; defined ( 'JSON_UNESCAPED_UNICODE' ) && $ options = JSON_UNESCAPED_UNICODE ; $ content = json_encode ( $ data , $ options ) ; if ( $ jsonp && preg_match ( '/^[$A-Z_][0-9A-Z_$.]*$/i' , $ this -> request [ 'callback' ] ) === 1 ) { $ this -> setHeader ( 'Content-Type' , 'application/javascript' ) ; $ content = $ this -> request [ 'callback' ] . '(' . $ content . ')' ; } else { $ this -> setHeader ( 'Content-Type' , 'application/json' ) ; } return $ this -> setContent ( $ content ) ; }
Response JSON or JSONP format string

@param mixed $data The variable to be convert to JSON string
@param bool $jsonp Whether allow response json format on demand
@return $this
Response JSON or JSONP format string