Decode JSON encoded string to PHP variable constructs

package Default

 Methods

Decode a JSON source string

decode(string $source, integer $objectDecodeType = \Zend\Json\Json::TYPE_OBJECT) : mixed
Static

Decodes a JSON encoded string. The value returned will be one of the following:

  • integer
  • float
  • boolean
  • null
    • stdClass
    • array
      • array of one or more of the above types

By default, decoded objects will be returned as associative arrays; to return a stdClass object instead, pass Zend\Json\Json::TYPE_OBJECT to the $objectDecodeType parameter.

static
access public

Parameters

$source

string

String to be decoded

$objectDecodeType

integer

How objects should be decoded; should be either or {@link Zend\Json\Json::TYPE_ARRAY} or {@link Zend\Json\Json::TYPE_OBJECT}; defaults to TYPE_ARRAY

Returns

mixed

Decode Unicode Characters from \u0000 ASCII syntax.

decodeUnicodeString(string $chrs) : string
Static

This algorithm was originally developed for the Solar Framework by Paul M. Jones

link http://solarphp.com/
link https://github.com/solarphp/core/blob/master/Solar/Json.php

Parameters

$chrs

string

Returns

string

Constructor

__construct(string $source, integer $decodeType) 

Parameters

$source

string

String source to decode

$decodeType

integer

How objects should be decoded -- see {@link Zend\Json\Json::TYPE_ARRAY} and {@link Zend\Json\Json::TYPE_OBJECT} for valid values

Exceptions

\Zend\Json\Exception\InvalidArgumentException

Decodes a JSON array format: [element, element2,.

_decodeArray() : array

..,elementN]

Exceptions

\Zend\Json\Exception\RuntimeException

Returns

array

Decodes an object of the form: { "attribute: value, "attribute2" : value,.

_decodeObject() : array | \stdClass

..}

If Zend\Json\Encoder was used to encode the original object then a special attribute called __className which specifies a class name that should wrap the data contained within the encoded source.

Decodes to either an array or stdClass object, based on the value of \$decodeType. If invalid $decodeType present, returns as an array.

Exceptions

\Zend\Json\Exception\RuntimeException

Returns

array\stdClass

Recursive driving routine for supported toplevel tops

_decodeValue() : mixed

Returns

mixed

Removes whitespace characters from the source input

_eatWhitespace() 

Retrieves the next token from the source stream

_getNextToken() : integer

Exceptions

\Zend\Json\Exception\RuntimeException

Returns

integerToken constant value specified in class definition

Convert a string from one UTF-16 char to one UTF-8 char.

_utf162utf8(string $utf16) : string
Static

Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibyte string extension.

This method is from the Solar Framework by Paul M. Jones

link http://solarphp.com

Parameters

$utf16

string

UTF-16 character

Returns

stringUTF-8 character

 Properties

 

Flag indicating how objects should be decoded

$decodeType : integer

Default

access protected
 

The offset within the source being decoded

$offset : integer

Default

 

Use to maintain a "pointer" to the source being decoded

$source : string

Default

 

Caches the source length

$sourceLength : integer

Default

 

The current token being considered in the parser cycle

$token : integer

Default

 

$tokenValue

$tokenValue : 

Default

 Constants

 

COLON

COLON = 7 
 

COMMA

COMMA = 6 
 

DATUM

DATUM = 1 
 

Parse tokens used to decode the JSON object. These are not for public consumption, they are just used internally to the class.

EOF = 0 
 

LBRACE

LBRACE = 2 
 

LBRACKET

LBRACKET = 3 
 

RBRACE

RBRACE = 4 
 

RBRACKET

RBRACKET = 5