render json string, 统一输出结果为 ['errcode'=>.., 'errmsg'=>.., 'somekey'=>..]

@param  array $data
@return ResponseInterface
18681
public function renderJson($data=null)
    {
        $this->beforeRender($data);
        
        return $this->renderText(json_encode($this->responseData->all()));
    }
420306
protected function jsonResponse($data = array())
    {
        $this->view->disable();
        $this->response->setContentType('application/json', 'UTF-8');

        return $this->response->setJsonContent($data);
    }
1374886
public function display($data, $params)
    {
        $this->getResponse()->setContentType('application/json; charset=utf-8;');
        $result = array();
        $header = array();
        //$messages = array();
        foreach ($this->messages as $message) {
            $result[$message['type']][] = $message['message'];
        }
        $header['date'] = date('Y-m-d H:i:s');
        $header['controller'] = get_class($this);
        $result['header'] = $header;
        if ($data instanceof Model || $data instanceof ModelResult) {
            $result['data'] = $data->json();
        } else {
            $result['data'] = $data;
        }
        $options = 0;
        if (isset($_GET['pretty'])) {
            $options = 128;
        }
        return json_encode($result, $options);
    }
279450
public function respondWithData(array $data)
    {

        $responseData = $this->getResponseStructure(true, $data, '');
        $response = new JsonResponse($responseData, $this->getStatusCode(), $this->getHeaders());
        return $response;
    }
125201
public function render($status = 200, $data = null) {
        $app = $this->app;
        $status = \intval($status);

        if ($this->dataWrapper) {
            $response[$this->dataWrapper] = $this->all();
        } else {
            $response = $this->all();
        }

        if (!$this->dataOnly) {
            //append error bool
            if ($status < 400) {
                if ($this->metaWrapper) {
                    $response[$this->metaWrapper]['error'] = false;
                } else {
                    $response['error'] = false;
                }
            } else {
                if ($this->metaWrapper) {
                    $response[$this->metaWrapper]['error'] = true;
                } else {
                    $response['error'] = true;
                }
            }

            //append status code

            if ($app->config(Config::Status)) {
                if ($this->metaWrapper) {
                    $response[$this->metaWrapper]['status'] = $status;
                } else {
                    $response['status'] = $status;
                }
            }

            //add flash messages
            if (isset($this->data->flash) && \is_object($this->data->flash)) {
                // if (isset($response['flash']) && \is_object($response['flash'])) {

                $flash = $this->data->flash->getMessages();

                if ($this->dataWrapper) {
                    unset($response[$this->dataWrapper]['flash']);
                } else {
                    unset($response['flash']);
                }

                if (count($flash)) {
                    if ($this->metaWrapper) {
                        $response[$this->metaWrapper]['flash'] = $flash;
                    } else {
                        $response['flash'] = $flash;
                    }
                }
            }
        } else {
            unset($response['flash'], $response['status'], $response['error']);
        }

        $app->response()->status($status);
        $app->response()->header('Content-Type', $this->contentType);

        $jsonp_callback = $app->request->get('callback', null);

        /**
         * Bitmask consisting of <b>JSON_HEX_QUOT</b>,
         * <b>JSON_HEX_TAG</b>,
         * <b>JSON_HEX_AMP</b>,
         * <b>JSON_HEX_APOS</b>,
         * <b>JSON_NUMERIC_CHECK</b>,
         * <b>JSON_PRETTY_PRINT</b>,
         * <b>JSON_UNESCAPED_SLASHES</b>,
         * <b>JSON_FORCE_OBJECT</b>,
         * <b>JSON_UNESCAPED_UNICODE</b>.
         * The behaviour of these constants is described on
         * the JSON constants page.
         * @var int
         */
        $encodingOptions = $app->config(Config::JsonEncodeOptions);

        if ($jsonp_callback !== null) {
            $body = $jsonp_callback . '(' . json_encode($response, $encodingOptions) . ')';
        } else {
            $body = json_encode($response, $encodingOptions);
        }

        if ($status == 404) {
            return $body;
        } else {
            $app->response()->body($body);
        }
    }
541801
protected function encodeData(array $data): string
    {
        $json = \json_encode(
            $data,
            JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
        );

        return \base64_encode($json);
    }
912424
public function jsonResponse($data = [])
	{
		global $db_show_debug;

		$json = '';
		$result = false;

		// Defensive programming anyone?
		if (empty($data))
			return false;

		// This is pretty simply, just encode the supplied data and be done with it.
		$json = json_encode($data);

		$result = json_last_error() == JSON_ERROR_NONE;

		if ($result)
		{
			// Don't need extra stuff...
			$db_show_debug = false;

			// Kill anything else
			ob_end_clean();

			if ($this->_app->modSetting('CompressedOutput'))
				@ob_start('ob_gzhandler');

			else
				ob_start();

			// Set the header.
			header('Content-Type: application/json');

			// Echo!
			echo $json;

			// Done
			obExit(false);
		}

		return $result;
	}
1027896
protected function renderHtml($data)
    {
        $html = $this->getHtmlPrefix();
        $html .= $this->arrayToHtml($data);
        $html .= $this->getHtmlPostfix();

        return $html;
    }
994518
public function jsonEncode($data)
    {
        if (is_array($data)) {
            $ret = "";
            $blWasOne = false;
            $blNumerical = true;
            reset($data);
            while ($blNumerical && $key = key($data)) {
                $blNumerical = !is_string($key);
            }
            if ($blNumerical) {
                return '[' . implode(',', array_map([$this, 'jsonEncode'], $data)) . ']';
            } else {
                foreach ($data as $key => $val) {
                    if ($blWasOne) {
                        $ret .= ',';
                    } else {
                        $blWasOne = true;
                    }
                    $ret .= '"' . addslashes($key) . '":' . $this->jsonEncode($val);
                }

                return "{" . $ret . "}";
            }
        } else {
            return '"' . addcslashes((string) $data, "\r\n\t\"\\") . '"';
        }
    }
479919
public function render(array $data = null) : string
    {
        if (null !== $data) {
            $this->bind($data);
        }
        return $this->twig->render($this->data);
    }
699284
private function _toJson($data)
    {
        if ($data) {
            if (is_array($data)) {
                return json_encode($this->_toCleanArray($data));
            }

            return json_encode($data);
        }
    }
297231
protected function error($errcode=-1, $errmsg=null, $data=null)
    {
        !isset($this->errorInfo['errcode']) && $this->errorInfo = ErrorInfo::error($errcode, $errmsg, $data);
        
        if (!isset($this->errorInfo['errmsg'])) {
            $this->errorInfo['errmsg'] = '操作失败';
        }
        
        return $this->jump($this->errorInfo);
    }
157794
public function renderMessageBox($data=null)
    {
        $this->beforeRender($data);
        
        $this->beforeRenderView();
        
        // use view inner view/message.html
        $output = $this->getView()->renderMessageBox($this->responseData()->all());
        
        return $this->renderText($output);
    }
252271
protected static function pretty_json($data)
	{
		$json = json_encode($data, \Config::get('format.json.encode.options', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP));

		if ( ! $json)
		{
			return false;
		}

		$tab = "\t";
		$newline = "\n";
		$new_json = "";
		$indent_level = 0;
		$in_string = false;
		$len = strlen($json);

		for ($c = 0; $c < $len; $c++)
		{
			$char = $json[$c];
			switch($char)
			{
				case '{':
				case '[':
					if ( ! $in_string)
					{
						$new_json .= $char.$newline.str_repeat($tab, $indent_level+1);
						$indent_level++;
					}
					else
					{
						$new_json .= $char;
					}
					break;
				case '}':
				case ']':
					if ( ! $in_string)
					{
						$indent_level--;
						$new_json .= $newline.str_repeat($tab, $indent_level).$char;
					}
					else
					{
						$new_json .= $char;
					}
					break;
				case ',':
					if ( ! $in_string)
					{
						$new_json .= ','.$newline.str_repeat($tab, $indent_level);
					}
					else
					{
						$new_json .= $char;
					}
					break;
				case ':':
					if ( ! $in_string)
					{
						$new_json .= ': ';
					}
					else
					{
						$new_json .= $char;
					}
					break;
				case '"':
					if ($c > 0 and $json[$c-1] !== '\\')
					{
						$in_string = ! $in_string;
					}
				default:
					$new_json .= $char;
					break;
			}
		}

		return $new_json;
	}
630623
private function arrayToHtml(array $data): string
    {
        $html = file_get_contents($this->path);

        foreach ($data as $key => $val) {
            $html = str_replace("{{ $$key }}", $val, $html);
        }

        return $html;
    }
378888
public function json( $data ) {
		$response = $this->response();
		$response = $response->withHeader( 'Content-Type', 'application/json' );
		$response = $response->withBody( Psr7\stream_for( wp_json_encode( $data ) ) );
		return $response;
	}
1129533
final public function render($data = array())
    {
        $context = $this->getContext();
        $context->data = array_merge($this->getData(), $data);

        if ($this->invokeCommand('before.render', $context) !== false)
        {
            //Render the view
            $context->result = $this->_actionRender($context);
            $this->invokeCommand('after.render', $context);
        }

        //Set the content
        $this->setContent($context->result);

        return $context->result;
    }