Decode JSON encoded string to PHP variable constructs

category Zend
package Zend_Json
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 Methods

Decode a JSON source string

decode(string $source = null, integer $objectDecodeType = \Zend_Json::TYPE_ARRAY) : 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::TYPE_OBJECT to the $objectDecodeType parameter.

Throws a Zend_Json_Exception if the source string is null.

static
access public

Parameters

$source

string

String to be decoded

$objectDecodeType

integer

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

Exceptions

\Zend_Json_Exception

Returns

mixed

Decode Unicode Characters from \u0000 ASCII syntax.

decodeUnicodeString($chrs) : string
Static

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

Returns

string

Constructor

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

Parameters

$source

string

String source to decode

$decodeType

integer

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

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

_decodeArray() : array

..,elementN]

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.

Returns

array\StdClass

Recursive driving rountine for supported toplevel tops

_decodeValue() : mixed

Returns

mixed

Removes whitepsace characters from the source input

_eatWhitespace() 

Retrieves the next token from the source stream

_getNextToken() : integer

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 multibye 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 souce 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

 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