Class yii\helpers\BaseJson

Inheritanceyii\helpers\BaseJson
Subclassesyii\helpers\Json
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseJson.php

BaseJson provides concrete implementation for yii\helpers\Json.

Do not use BaseJson. Use yii\helpers\Json instead.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
decode() Decodes the given JSON string into a PHP data structure. yii\helpers\BaseJson
encode() Encodes the given value into a JSON string. yii\helpers\BaseJson
htmlEncode() Encodes the given value into a JSON string HTML-escaping entities so it is safe to be embedded in HTML code. yii\helpers\BaseJson

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
processData() Pre-processes the data before sending it to json_encode(). yii\helpers\BaseJson

Method Details

decode() public method

Decodes the given JSON string into a PHP data structure.

mixed decode$json$asArray true )
$json string

The JSON string to be decoded

$asArray boolean

Whether to return objects in terms of associative arrays.

return mixed

The PHP data

throws yii\base\InvalidParamException

if there is any decoding error

encode() public method

Encodes the given value into a JSON string.

The method enhances json_encode() by supporting JavaScript expressions. In particular, the method will not encode a JavaScript expression that is represented in terms of a yii\web\JsExpression object.

string encode$value$options 320 )
$value mixed

The data to be encoded

$options integer

The encoding options. For more details please refer to http://www.php.net/manual/en/function.json-encode.php. Default is JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE.

return string

The encoding result

htmlEncode() public method (available since version 2.0.4)

Encodes the given value into a JSON string HTML-escaping entities so it is safe to be embedded in HTML code.

The method enhances json_encode() by supporting JavaScript expressions. In particular, the method will not encode a JavaScript expression that is represented in terms of a yii\web\JsExpression object.

string htmlEncode$value )
$value mixed

The data to be encoded

return string

The encoding result

processData() protected method

Pre-processes the data before sending it to json_encode().

mixed processData$data, <b>&</b>$expressions$expPrefix )
$data mixed

The data to be processed

$expressions array

Collection of JavaScript expressions

$expPrefix string

A prefix internally used to handle JS expressions

return mixed

The processed data