Source for file json.php

Documentation is available at json.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Registry
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * JSON format handler for JRegistry.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Registry
  17.  * @since       11.1
  18.  */
  19. {
  20.     /**
  21.      * Converts an object into a JSON formatted string.
  22.      *
  23.      * @param   object  $object   Data source object.
  24.      * @param   array   $options  Options used by the formatter.
  25.      *
  26.      * @return  string  JSON formatted string.
  27.      *
  28.      * @since   11.1
  29.      */
  30.     public function objectToString($object$options array())
  31.     {
  32.         return json_encode($object);
  33.     }
  34.  
  35.     /**
  36.      * Parse a JSON formatted string and convert it into an object.
  37.      *
  38.      * If the string is not in JSON format, this method will attempt to parse it as INI format.
  39.      *
  40.      * @param   string  $data     JSON formatted string to convert.
  41.      * @param   array   $options  Options used by the formatter.
  42.      *
  43.      * @return  object   Data object.
  44.      *
  45.      * @since   11.1
  46.      */
  47.     public function stringToObject($dataarray $options array('processSections' => false))
  48.     {
  49.         $data trim($data);
  50.  
  51.         if ((substr($data01!= '{'&& (substr($data-11!= '}'))
  52.         {
  53.             $ini JRegistryFormat::getInstance('INI');
  54.             $obj $ini->stringToObject($data$options);
  55.         }
  56.         else
  57.         {
  58.             $obj json_decode($data);
  59.         }
  60.  
  61.         return $obj;
  62.     }
  63. }

Documentation generated on Tue, 19 Nov 2013 15:06:17 +0100 by phpDocumentor 1.4.3