PHP Class yii\helpers\BaseJson

Do not use BaseJson. Use [[Json]] instead.
Since: 2.0
Author: Qiang Xue ([email protected])
Exibir arquivo Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$jsonErrorMessages array List of JSON Error messages assigned to constant names for better handling of version differences

Public Methods

Method Description
decode ( string $json, boolean $asArray = true ) : mixed Decodes the given JSON string into a PHP data structure.
encode ( mixed $value, integer $options = 320 ) : string Encodes the given value into a JSON string.
htmlEncode ( mixed $value ) : string Encodes the given value into a JSON string HTML-escaping entities so it is safe to be embedded in HTML code.

Protected Methods

Method Description
handleJsonError ( integer $lastError ) Handles BaseJson::encode and BaseJson::decode errors by throwing exceptions with the respective error message.
processData ( mixed $data, array &$expressions, string $expPrefix ) : mixed Pre-processes the data before sending it to json_encode().

Method Details

decode() public static method

Decodes the given JSON string into a PHP data structure.
public static decode ( string $json, boolean $asArray = true ) : mixed
$json string the JSON string to be decoded
$asArray boolean whether to return objects in terms of associative arrays.
return mixed the PHP data

encode() public static method

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 [[JsExpression]] object.
public static encode ( mixed $value, integer $options = 320 ) : string
$value mixed the data to be encoded.
$options integer the encoding options. For more details please refer to . Default is `JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE`.
return string the encoding result.

handleJsonError() protected static method

Handles BaseJson::encode and BaseJson::decode errors by throwing exceptions with the respective error message.
Since: 2.0.6
protected static handleJsonError ( integer $lastError )
$lastError integer error code from [json_last_error()](http://php.net/manual/en/function.json-last-error.php).

htmlEncode() public static method

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 [[JsExpression]] object.
Since: 2.0.4
public static htmlEncode ( mixed $value ) : string
$value mixed the data to be encoded
return string the encoding result

processData() protected static method

Pre-processes the data before sending it to json_encode().
protected static processData ( mixed $data, array &$expressions, string $expPrefix ) : mixed
$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

Property Details

$jsonErrorMessages public_oe static_oe property

List of JSON Error messages assigned to constant names for better handling of version differences
Since: 2.0.7
public static array $jsonErrorMessages
return array