Zend Framework  3.0
Static Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | List of all members
Json Class Reference

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.
 

Detailed Description

Class for encoding to and decoding from JSON.

Member Function Documentation

static decode (   $encodedValue,
  $objectDecodeType = self::TYPE_OBJECT 
)
static

Decodes the given $encodedValue string from JSON.

Uses json_decode() from ext/json if available.

Parameters
string$encodedValueEncoded in JSON format
int$objectDecodeTypeOptional; flag indicating how to decode objects. See Decoder::decode() for details.
Returns
mixed
Exceptions
RuntimeException
static encode (   $valueToEncode,
  $cycleCheck = false,
array  $options = [] 
)
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

See Also
Zend
Parameters
mixed$valueToEncode
bool$cycleCheckOptional; whether or not to check for object recursion; off by default
array$optionsAdditional options used during encoding
Returns
string JSON encoded object
static prettyPrint (   $json,
array  $options = [] 
)
static

Pretty-print JSON string.

Use 'indent' option to select indentation string; by default, four spaces are used.

Parameters
string$jsonOriginal JSON string
array$optionsEncoding options
Returns
string
static recursiveJsonExprFinder (   $value,
SplQueue  $javascriptExpressions,
  $currentKey = null 
)
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.

See Also
encode
Parameters
mixed$valuea string - object property to be encoded
SplQueue$javascriptExpressions
null | string | int$currentKey
Returns
mixed

Member Data Documentation

$useBuiltinEncoderDecoder = false
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