Json.php

Show: PublicProtectedPrivateinherited
Table of Contents
Zend Framework
LICENSE This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Json  
Version
$Id$  

\Zend_Json

Package: Zend_Json
Class for encoding to and decoding from JSON.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Uses
 

Constants

>VConstant  TYPE_ARRAY = 1
How objects should be encoded -- arrays or as StdClass. TYPE_ARRAY is 1 so that it is a boolean true value, allowing it to be used with ext/json's functions.
>VConstant  TYPE_OBJECT = 0

Properties

>VPropertypublicint $maxRecursionDepthAllowed = 25
static
To check the allowed nesting depth of the XML tree during xml2json conversion.
Default value25Details
Type
int
>VPropertypublicbool $useBuiltinEncoderDecoder = false
static
Default valuefalseDetails
Type
bool

Methods

methodprotected_getXmlValue(\SimpleXMLElement $simpleXmlElementObject) : \Zend_Json_Expr | string
static

Return the value of an XML attribute text or the text between the XML tags

In order to allow Zend_Json_Expr from xml, we check if the node matchs the pattern that try to detect if it is a new Zend_Json_Expr if it matches, we return a new Zend_Json_Expr instead of a text node
Parameters
NameTypeDescription
$simpleXmlElementObject\SimpleXMLElement
Returns
TypeDescription
\Zend_Json_Expr | string
methodprotected_processXml(\SimpleXMLElement $simpleXmlElementObject, boolean $ignoreXmlAttributes, integer $recursionDepth = 0) : array
static

_processXml - Contains the logic for xml2json

The logic in this function is a recursive one. The main caller of this function (i.e. fromXml) needs to provide only the first two parameters i.e. the SimpleXMLElement object and the flag for ignoring or not ignoring XML attributes. The third parameter will be used internally within this function during the recursive calls. This function converts the SimpleXMLElement object into a PHP array by calling a recursive (protected static) function in this class. Once all the XML elements are stored in the PHP array, it is returned to the caller. Throws a Zend_Json_Exception if the XML tree is deeper than the allowed limit.
Parameters
NameTypeDescription
$simpleXmlElementObject\SimpleXMLElement
$ignoreXmlAttributesboolean
$recursionDepthinteger
Returns
TypeDescription
array
methodpublicdecode(string $encodedValue, int $objectDecodeType = \Zend_Json::TYPE_ARRAY) : mixed
static

Decodes the given $encodedValue string which is encoded in the JSON format

Uses ext/json's json_decode if available.
Parameters
NameTypeDescription
$encodedValuestring

Encoded in JSON format

$objectDecodeTypeint

Optional; flag indicating how to decode objects. See {@link Zend_Json_Decoder::decode()} for details.

Returns
TypeDescription
mixed
methodpublicencode(mixed $valueToEncode, boolean $cycleCheck = false, array $options = array()) : string
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_Json_Expr. You can enable this by setting $options['enableJsonExprFinder'] = true
Parameters
NameTypeDescription
$valueToEncodemixed
$cycleCheckboolean

Optional; whether or not to check for object recursion; off by default

$optionsarray

Additional options used during encoding

Returns
TypeDescription
stringJSON encoded object
Details
See
 
methodpublicfromXml(string $xmlStringContents, boolean $ignoreXmlAttributes = true) : mixed
static

fromXml - Converts XML to JSON

Converts a XML formatted string into a JSON formatted string. The value returned will be a string in JSON format. The caller of this function needs to provide only the first parameter, which is an XML formatted String. The second parameter is optional, which lets the user to select if the XML attributes in the input XML string should be included or ignored in xml2json conversion. This function converts the XML formatted string into a PHP array by calling a recursive (protected static) function in this class. Then, it converts that PHP array into JSON by calling the "encode" static funcion. Throws a Zend_Json_Exception if the input not a XML formatted string. NOTE: Encoding native javascript expressions via Zend_Json_Expr is not possible.
Parameters
NameTypeDescription
$xmlStringContentsstring

XML String to be converted

$ignoreXmlAttributesboolean

Include or exclude XML attributes in the xml2json conversion process.

Returns
TypeDescription
mixed- JSON formatted string on success
Throws
ExceptionDescription
\Zend_Json_Exception
Details
Access
public  
Static
 
methodpublicprettyPrint(string $json, array $options = array()) : string
static

Pretty-print JSON string

Use 'format' option to select output format - currently html and txt supported, txt is default Use 'indent' option to override the indentation string set in the format - by default for the 'txt' format it's a tab
Parameters
NameTypeDescription
$jsonstring

Original JSON string

$optionsarray

Encoding options

Returns
TypeDescription
string
Documentation was generated by phpDocumentor 2.2.0 .