Zend Framework
3.0
|
Class for encoding to and decoding from JSON. More...
Static Public Member Functions | |
static | decode ($encodedValue, $objectDecodeType=self::TYPE_OBJECT) |
Decodes the given $encodedValue string from JSON. | |
static | encode ($valueToEncode, $cycleCheck=false, array $options=[]) |
Encode the mixed $valueToEncode into the JSON format. | |
static | prettyPrint ($json, array $options=[]) |
Pretty-print JSON string. | |
Public Attributes | |
const | TYPE_ARRAY = 1 |
How objects should be encoded: as arrays or as stdClass. | |
const | TYPE_OBJECT = 0 |
Static Public Attributes | |
static | $useBuiltinEncoderDecoder = false |
Static Protected Member Functions | |
static | recursiveJsonExprFinder ($value, SplQueue $javascriptExpressions, $currentKey=null) |
Discover and replace javascript expressions with temporary placeholders. | |
Class for encoding to and decoding from JSON.
|
static |
Decodes the given $encodedValue string from JSON.
Uses json_decode() from ext/json if available.
string | $encodedValue | Encoded in JSON format |
int | $objectDecodeType | Optional; flag indicating how to decode objects. See Decoder::decode() for details. |
RuntimeException |
|
static |
Encode the mixed $valueToEncode into the JSON format.
Encodes using ext/json's json_encode() if available.
NOTE: Object should not contain cycles; the JSON format does not allow object reference.
NOTE: Only public variables will be encoded
NOTE: Encoding native javascript expressions are possible using Zend. You can enable this by setting $options['enableJsonExprFinder'] = true
mixed | $valueToEncode | |
bool | $cycleCheck | Optional; whether or not to check for object recursion; off by default |
array | $options | Additional options used during encoding |
|
static |
Pretty-print JSON string.
Use 'indent' option to select indentation string; by default, four spaces are used.
string | $json | Original JSON string |
array | $options | Encoding options |
|
staticprotected |
Discover and replace javascript expressions with temporary placeholders.
Check each value to determine if it is a Zend; if so, replace the value with a magic key and add the javascript expression to the queue.
NOTE this method is recursive.
NOTE: This method is used internally by the encode method.
mixed | $value | a string - object property to be encoded |
SplQueue | $javascriptExpressions | |
null | string | int | $currentKey |
|
static |
const TYPE_ARRAY = 1 |
How objects should be encoded: as arrays or as stdClass.
TYPE_ARRAY is 1, which also conveniently evaluates to a boolean true value, allowing it to be used with ext/json's functions.
const TYPE_OBJECT = 0 |