Swoole\Controller::json PHP Method

json() public method

输出JSON字串
public json ( string $data = '', integer $code, string $message = '' ) : string
$data string
$code integer
$message string
return string
    function json($data = '', $code = 0, $message = '')
    {
        $json = array('code' => $code, 'message' => $message, 'data' => $data);
        if (!empty($_REQUEST['jsonp'])) {
            $this->http->header('Content-type', 'application/x-javascript');
            return $_REQUEST['jsonp'] . "(" . json_encode($json) . ");";
        } else {
            $this->http->header('Content-type', 'application/json');
            return json_encode($json);
        }
    }