.

GyroJSON Class Reference
[JSON]

Convertes from and to JSON Use either directly or through ConverterFactory like this: More...

Inheritance diagram for GyroJSON:
IConverter

List of all members.

Public Member Functions

  decode ($str, $params=false)
  Decode string to data.
  encode ($data, $params=false)
  Turns data in a JSON string.

Detailed Description

Convertes from and to JSON Use either directly or through ConverterFactory like this:

 // To JSON
 $json_string = ConverterFactory::encode($data, CONVERTER_JSON);
 // Back from JSON to data structure
 $data = ConverterFactory::decode($json_string, CONVERTER_JSON);
Author:
Gerd Riesselmann

Definition at line 16 of file json.cls.php.


Member Function Documentation

GyroJSON::decode ( str,
params = false  
)

Decode string to data.

Parameters:
string  $str
Returns:
mixed

Implements IConverter.

Definition at line 23 of file json.cls.php.

00023                                                       {
00024                 $ret = false;
00025                 if (function_exists('json_decode')) {
00026                         // PHP 5.2 or PECL extension
00027                         // There is a bug in json_decode and floating values before PHP 5.2.2
00028                         // http://bugs.php.net/bug.php?id=41403 
00029                         $cur_locale = setlocale(LC_NUMERIC, '0');
00030                         setlocale(LC_NUMERIC, 'C'); // system
00031                         $ret = json_decode($str);
00032                         setlocale(LC_NUMERIC, $cur_locale); // back
00033                         return $ret;
00034                 }
00035                 else {
00036                         // Try PEAR Package Services_JSON
00037                         include_once 'Services/JSON.php';
00038                         if (class_exists('Services_JSON')) {
00039                                 $json = new Services_JSON();
00040                                 return $json->decode($str);
00041                         }
00042                 }
00043                 throw new Exception(tr('No JSON implementation found', 'ajax'));                
00044         }
GyroJSON::encode ( data,
params = false  
)

Turns data in a JSON string.

Parameters:
mixed  $data
Returns:
string

Implements IConverter.

Definition at line 52 of file json.cls.php.

00052                                                        {
00053                 if (function_exists('json_encode')) {
00054                         // PHP 5.2 or PECL extension
00055                         // There is a bug in json_encode and floating values before PHP 5.2.2
00056                         // http://bugs.php.net/bug.php?id=41403 
00057                         $cur_locale = setlocale(LC_NUMERIC, '0');
00058                         setlocale(LC_NUMERIC, 'C'); // system
00059                         $ret = json_encode($data);
00060                         setlocale(LC_NUMERIC, $cur_locale); // back
00061                         return $ret;
00062                 }
00063                 // Try PEAR Package Services_JSON
00064                 include_once 'Services/JSON.php';
00065                 if (class_exists('Services_JSON')) {
00066                         $json = new Services_JSON();
00067                         return $json->encode($str);
00068                 }
00069                 throw new Exception(tr('No JSON implementation found', 'ajax'));                
00070         }

The documentation for this class was generated from the following file: