public function setJsonContent($content)
    {
        $context = $this->_context;

        $this->setHeader('Content-Type', 'application/json; charset=utf-8');

        if (is_array($content)) {
            if (!isset($content['code'])) {
                $content = ['code' => 0, 'message' => '', 'data' => $content];
            }
        } elseif ($content instanceof \JsonSerializable) {
            $content = ['code' => 0, 'message' => '', 'data' => $content];
        } elseif (is_string($content)) {
            null;
        } elseif (is_int($content)) {
            $content = ['code' => $content, 'message' => ''];
        } elseif ($content === null) {
            $content = ['code' => 0, 'message' => '', 'data' => null];
        } elseif ($content instanceof ValidatorException) {
            $content = ['code' => -2, 'message' => $content->getMessage()];
        } elseif ($content instanceof \Exception) {
            if ($content instanceof \ManaPHP\Exception) {
                $this->setStatus($content->getStatusCode());
                $content = $content->getJson();
            } else {
                $this->setStatus(500);
                $content = ['code' => 500, 'message' => 'Server Internal Error'];
            }
        }

        $context->content = $this->_jsonEncode($content);

        return $this;
    }
public function setJsonContent($content)
    {
        $context = $this->_context;

        $this->setHeader('Content-Type', 'application/json; charset=utf-8');

        if (is_array($content)) {
            if (!isset($content['code'])) {
                $content = ['code' => 0, 'message' => '', 'data' => $content];
            }
        } elseif ($content instanceof \JsonSerializable) {
            $content = ['code' => 0, 'message' => '', 'data' => $content];
        } elseif (is_string($content)) {
            null;
        } elseif (is_int($content)) {
            $content = ['code' => $content, 'message' => ''];
        } elseif ($content === null) {
            $content = ['code' => 0, 'message' => '', 'data' => null];
        } elseif ($content instanceof ValidatorException) {
            $content = ['code' => -2, 'message' => $content->getMessage()];
        } elseif ($content instanceof \Exception) {
            if ($content instanceof \ManaPHP\Exception) {
                $this->setStatus($content->getStatusCode());
                $content = $content->getJson();
            } else {
                $this->setStatus(500);
                $content = ['code' => 500, 'message' => 'Server Internal Error'];
            }
        }

        $context->content = $this->_jsonEncode($content);

        return $this;
    }
public function setJsonContent ( $ content ) { $ context = $ this -> _context ; $ this -> setHeader ( 'Content-Type' , 'application/json; charset=utf-8' ) ; if ( is_array ( $ content ) ) { if ( ! isset ( $ content [ 'code' ] ) ) { $ content = [ 'code' => 0 , 'message' => '' , 'data' => $ content ] ; } } elseif ( $ content instanceof \ JsonSerializable ) { $ content = [ 'code' => 0 , 'message' => '' , 'data' => $ content ] ; } elseif ( is_string ( $ content ) ) { null ; } elseif ( is_int ( $ content ) ) { $ content = [ 'code' => $ content , 'message' => '' ] ; } elseif ( $ content === null ) { $ content = [ 'code' => 0 , 'message' => '' , 'data' => null ] ; } elseif ( $ content instanceof ValidatorException ) { $ content = [ 'code' => - 2 , 'message' => $ content -> getMessage ( ) ] ; } elseif ( $ content instanceof \ Exception ) { if ( $ content instanceof \ ManaPHP \ Exception ) { $ this -> setStatus ( $ content -> getStatusCode ( ) ) ; $ content = $ content -> getJson ( ) ; } else { $ this -> setStatus ( 500 ) ; $ content = [ 'code' => 500 , 'message' => 'Server Internal Error' ] ; } } $ context -> content = $ this -> _jsonEncode ( $ content ) ; return $ this ; }
Sets HTTP response body. The parameter is automatically converted to JSON

@param array|\JsonSerializable|int|string|\Exception $content

@return static
Sets HTTP response body . The parameter is automatically converted to JSON