openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

JSON.class.php (890B)


      1 <?php
      2 
      3 
      4 namespace util\json;
      5 
      6 require(__DIR__.'/../JSON.class.php');
      7 
      8 /**
      9  * JSON Wrapper.
     10  */
     11 class JSON
     12 {
     13 	public static function encode($jsonObj) {
     14 
     15 		if (function_exists('json_encode'))
     16 		{
     17 			// Native Methode ist schneller..
     18 			if ( version_compare(PHP_VERSION, '5.5', '>=' ) )
     19 				$jsonOptions = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK | JSON_PARTIAL_OUTPUT_ON_ERROR;
     20 			else
     21 				$jsonOptions = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK;
     22 
     23 			return json_encode($jsonObj, $jsonOptions);
     24 		}
     25 		else
     26 		{
     27 			// Fallback, falls json_encode() nicht existiert...
     28 			$json = new \JSON();
     29 			return $json->encode($jsonObj);
     30 		}
     31 
     32 	}
     33 	public static function decode($jsonText) {
     34 
     35 		if (function_exists('json_decode')) {
     36 			return json_decode( $jsonText,true );
     37 		} else {
     38 			$json = new JSON();
     39 			return $json->decode($jsonText);
     40 		}
     41 	}
     42 }