|
static | decode ($encodedValue, $objectDecodeType=self::TYPE_OBJECT) |
| Decodes the given $encodedValue string which is encoded in the JSON format.
|
|
static | encode ($valueToEncode, $cycleCheck=false, $options=array()) |
| Encode the mixed $valueToEncode into the JSON format.
|
|
static | fromXml ($xmlStringContents, $ignoreXmlAttributes=true) |
|
static | prettyPrint ($json, $options=array()) |
| Pretty-print JSON string.
|
|
Class for encoding to and decoding from JSON.
static _processXml |
( |
|
$simpleXmlElementObject, |
|
|
|
$ignoreXmlAttributes, |
|
|
|
$recursionDepth = 0 |
|
) |
| |
|
staticprotected |
_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.
- Parameters
-
SimpleXMLElement | $simpleXmlElementObject | |
bool | $ignoreXmlAttributes | |
int | $recursionDepth | |
- Exceptions
-
Exception\RecursionException | if the XML tree is deeper than the allowed limit. |
- Returns
- array
static _recursiveJsonExprFinder |
( |
& |
$value, |
|
|
array & |
$javascriptExpressions, |
|
|
|
$currentKey = null |
|
) |
| |
|
staticprotected |
Check & Replace Zend for tmp ids in the valueToEncode.
Check if the value is a Zend, 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 Also
- encode
- Parameters
-
mixed | $value | a string - object property to be encoded |
array | $javascriptExpressions | |
null | string | int | $currentKey | |
- Returns
- mixed
static encode |
( |
|
$valueToEncode, |
|
|
|
$cycleCheck = false , |
|
|
|
$options = array() |
|
) |
| |
|
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. You can enable this by setting $options['enableJsonExprFinder'] = true
- See Also
- Zend
- Parameters
-
mixed | $valueToEncode | |
bool | $cycleCheck | Optional; whether or not to check for object recursion; off by default |
array | $options | Additional options used during encoding |
- Returns
- string JSON encoded object
static fromXml |
( |
|
$xmlStringContents, |
|
|
|
$ignoreXmlAttributes = true |
|
) |
| |
|
static |
- 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 is not possible.
public
- Parameters
-
string | $xmlStringContents | XML String to be converted |
bool | $ignoreXmlAttributes | Include or exclude XML attributes in the xml2json conversion process. |
- Returns
- mixed - JSON formatted string on success
- Exceptions
-
\Zend\Json\Exception\RuntimeException | if the input not a XML formatted string |