web/lib/Zend/Json.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Json
    16  * @package    Zend_Json
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Json.php 24593 2012-01-05 20:35:02Z matthew $
    19  * @version    $Id$
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * Zend_Json_Expr.
    23  * Zend_Json_Expr.
    24  *
    24  *
    25  * @see Zend_Json_Expr
    25  * @see Zend_Json_Expr
    26  */
    26  */
    27 require_once 'Zend/Json/Expr.php';
    27 require_once 'Zend/Json/Expr.php';
    28 
    28 
       
    29 /** @see Zend_Xml_Security */
       
    30 require_once 'Zend/Xml/Security.php';
    29 
    31 
    30 /**
    32 /**
    31  * Class for encoding to and decoding from JSON.
    33  * Class for encoding to and decoding from JSON.
    32  *
    34  *
    33  * @category   Zend
    35  * @category   Zend
    34  * @package    Zend_Json
    36  * @package    Zend_Json
    35  * @uses       Zend_Json_Expr
    37  * @uses       Zend_Json_Expr
    36  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    38  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    39  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    38  */
    40  */
    39 class Zend_Json
    41 class Zend_Json
    40 {
    42 {
    41     /**
    43     /**
    75         if (function_exists('json_decode') && self::$useBuiltinEncoderDecoder !== true) {
    77         if (function_exists('json_decode') && self::$useBuiltinEncoderDecoder !== true) {
    76             $decode = json_decode($encodedValue, $objectDecodeType);
    78             $decode = json_decode($encodedValue, $objectDecodeType);
    77 
    79 
    78             // php < 5.3
    80             // php < 5.3
    79             if (!function_exists('json_last_error')) {
    81             if (!function_exists('json_last_error')) {
    80                 if ($decode === $encodedValue) {
    82                 if (strtolower($encodedValue) === 'null') {
       
    83                     return null;
       
    84                 } elseif ($decode === null) {
    81                     require_once 'Zend/Json/Exception.php';
    85                     require_once 'Zend/Json/Exception.php';
    82                     throw new Zend_Json_Exception('Decoding failed');
    86                     throw new Zend_Json_Exception('Decoding failed');
    83                 }
    87                 }
    84             // php >= 5.3
    88             // php >= 5.3
    85             } elseif (($jsonLastErr = json_last_error()) != JSON_ERROR_NONE) {
    89             } elseif (($jsonLastErr = json_last_error()) != JSON_ERROR_NONE) {
   339      * @throws Zend_Json_Exception
   343      * @throws Zend_Json_Exception
   340      */
   344      */
   341     public static function fromXml($xmlStringContents, $ignoreXmlAttributes=true)
   345     public static function fromXml($xmlStringContents, $ignoreXmlAttributes=true)
   342     {
   346     {
   343         // Load the XML formatted string into a Simple XML Element object.
   347         // Load the XML formatted string into a Simple XML Element object.
   344         $simpleXmlElementObject = simplexml_load_string($xmlStringContents);
   348         $simpleXmlElementObject = Zend_Xml_Security::scan($xmlStringContents);
   345 
   349 
   346         // If it is not a valid XML content, throw an exception.
   350         // If it is not a valid XML content, throw an exception.
   347         if ($simpleXmlElementObject == null) {
   351         if ($simpleXmlElementObject == null) {
   348             require_once 'Zend/Json/Exception.php';
   352             require_once 'Zend/Json/Exception.php';
   349             throw new Zend_Json_Exception('Function fromXml was called with an invalid XML formatted string.');
   353             throw new Zend_Json_Exception('Function fromXml was called with an invalid XML formatted string.');