decode()
encode()
fromXml()
prettyPrint()
_getXmlValue()
_processXml()
_recursiveJsonExprFinder()
$maxRecursionDepthAllowed
$useBuiltinEncoderDecoder
TYPE_ARRAY
TYPE_OBJECT
Class for encoding to and decoding from JSON.
decode(string $encodedValue, int $objectDecodeType) : mixed
Uses ext/json's json_decode if available.
string
Encoded in JSON format
int
Optional; flag indicating how to decode objects. See {@link Zend\Json\Decoder::decode()} for details.
\Zend\Json\Exception\RuntimeException |
---|
mixed
encode(mixed $valueToEncode, bool $cycleCheck, array $options) : string
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
see | \Zend\Json\Expr |
---|
mixed
bool
Optional; whether or not to check for object recursion; off by default
array
Additional options used during encoding
string
JSON encoded objectfromXml(string $xmlStringContents, bool $ignoreXmlAttributes) : mixed
deprecated | by https://github.com/zendframework/zf2/pull/6778 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 function. NOTE: Encoding native javascript expressions via Zend\Json\Expr is not possible. |
---|---|
static | |
access | public |
string
XML String to be converted
bool
Include or exclude XML attributes in the xml2json conversion process.
\Zend\Json\Exception\RuntimeException |
if the input not a XML formatted string |
---|
mixed
- JSON formatted string on successprettyPrint(string $json, array $options) : string
Use 'indent' option to select indentation string - by default it's a tab
string
Original JSON string
array
Encoding options
string
_getXmlValue(\SimpleXMLElement $simpleXmlElementObject) : \Zend\Json\Expr | string
In order to allow Zend\Json\Expr from xml, we check if the node matches 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
\SimpleXMLElement
\Zend\Json\Expr
string
_processXml(\SimpleXMLElement $simpleXmlElementObject, bool $ignoreXmlAttributes, int $recursionDepth) : array
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.
\SimpleXMLElement
bool
int
\Zend\Json\Exception\RecursionException |
if the XML tree is deeper than the allowed limit. |
---|
array
_recursiveJsonExprFinder(mixed $value, array $javascriptExpressions, null | string | int $currentKey) : mixed
Check if the value is a Zend\Json\Expr, and if replace its value with a magic key and save the javascript expression in an array.
NOTE this method is recursive.
NOTE: This method is used internally by the encode method.
see | \Zend\Json\encode |
---|
mixed
a string - object property to be encoded
array
nullstringint
mixed
$maxRecursionDepthAllowed : int
$useBuiltinEncoderDecoder : bool
TYPE_ARRAY
TYPE_ARRAY is 1 so that it is a boolean true value, allowing it to be used with ext/json's functions.
TYPE_OBJECT