class \mpf\web\helpers\JSON

class \mpf\web\helpers\JSON

Inheritance \mpf\base\Object
Implements -
Uses -
Childs -
Available since version  0.1
Source Code https://github.com/mpf-soft/mpf/tree/master/web/helpers/JSON.php

-no description found-

Attributes
public static \mpf\web\helpers\array @since $jsonErrorMessages = {"JSON_ERROR_DEPTH":"The maximum stack depth has been exceeded.","JSON_ERROR_STATE_MISMATCH":"Invalid or malformed JSON.","JSON_ERROR_CTRL_CHAR":"Control character error, possibly incorrectly encoded.","JSON_ERROR_SYNTAX":"Syntax error.","JSON_ERROR_UTF8":"Malformed UTF-8 characters, possibly incorrectly encoded.","JSON_ERROR_RECURSION":"One or more recursive references in the value to be encoded.","JSON_ERROR_INF_OR_NAN":"One or more NAN or INF values in the value to be encoded","JSON_ERROR_UNSUPPORTED_TYPE":"A value of a type that cannot be encoded was given"}

List of JSON Error messages assigned to constant names for better handling of version differences

Methods

public static string encode (mixed $value, int $options = 320)

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 [[JsExpression]] object.

public static string htmlEncode (mixed $value)

  • $value

    the data to be encoded

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 [[JsExpression]] object.

public static mixed decode (string $json, bool $asArray = true)

  • $json

    the JSON string to be decoded

  • $asArray

    whether to return objects in terms of associative arrays.

Decodes the given JSON string into a PHP data structure.

protected static mixed handleJsonError (int $lastError)

Handles [[encode()]] and [[decode()]] errors by throwing exceptions with the respective error message.

protected static mixed processData (mixed $data, array $expressions, string $expPrefix)

  • $data

    the data to be processed

  • $expressions

    collection of JavaScript expressions

  • $expPrefix

    a prefix internally used to handle JS expressions

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