PHP Класс yii\helpers\BaseJson

Do not use BaseJson. Use [[Json]] instead.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$jsonErrorMessages array List of JSON Error messages assigned to constant names for better handling of version differences

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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().

Описание методов

decode() публичный статический Метод

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.
Результат mixed the PHP data

encode() публичный статический Метод

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`.
Результат string the encoding result.

handleJsonError() защищенный статический Метод

Handles BaseJson::encode and BaseJson::decode errors by throwing exceptions with the respective error message.
С версии: 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() публичный статический Метод

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.
С версии: 2.0.4
public static htmlEncode ( mixed $value ) : string
$value mixed the data to be encoded
Результат string the encoding result

processData() защищенный статический Метод

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
Результат mixed the processed data

Описание свойств

$jsonErrorMessages публичное статическое свойство

List of JSON Error messages assigned to constant names for better handling of version differences
С версии: 2.0.7
public static array $jsonErrorMessages
Результат array