Decode JSON encoded string to PHP variable constructs

category Zend
package Zend_Json

 Methods

Decode a JSON source string

decode(string $source, int $objectDecodeType) : mixed

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::TYPE_OBJECT to the $objectDecodeType parameter.

static
access public

Parameters

$source

string

String to be decoded

$objectDecodeType

int

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

Returns

mixed

Decode Unicode Characters from \u0000 ASCII syntax.

decodeUnicodeString(string $chrs) : string

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

link http://solarphp.com/
link http://svn.solarphp.com/core/trunk/Solar/Json.php

Parameters

$chrs

string

Returns

string

Constructor

__construct(string $source, int $decodeType) : void

Parameters

$source

string

String source to decode

$decodeType

int

How objects should be decoded -- see {@link Zend_Json::TYPE_ARRAY} and {@link Zend_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() : int

Exceptions

\Zend\Json\Exception\RuntimeException

Returns

intToken constant value specified in class definition

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

_utf162utf8(string $utf16) : string

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 : int

access protected
 

The offset within the source being decoded

$offset : int

 

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

$source : string

 

Caches the source length

$sourceLength : int

 

The current token being considered in the parser cycle

$token : int

 

$tokenValue

$tokenValue : \Zend\Json\$_tokenValue

 Constants

 

COLON

COLON 

 

COMMA

COMMA 

 

DATUM

DATUM 

 

Parse tokens used to decode the JSON object.

EOF 

These are not for public consumption, they are just used internally to the class.

 

LBRACE

LBRACE 

 

LBRACKET

LBRACKET 

 

RBRACE

RBRACE 

 

RBRACKET

RBRACKET