Example #1
0
 /**
  * Creates a variable, array or object from any passed JSON string.
  *
  * If json_encode() exists it's done by that, otherwise an external class provided with the Shopgate Library is used.
  *
  * @param $json
  * @param bool $assoc
  * @return mixed
  */
 public function jsonDecode($json, $assoc = false)
 {
     // if json_decode exists use that
     if (extension_loaded('json') && function_exists('json_decode')) {
         return json_decode($json, $assoc);
     }
     // if not check if external class is loaded
     if (!class_exists('sgServicesJSON')) {
         require_once dirname(__FILE__) . '/../vendors/JSON.php';
     }
     // decode via external class
     $jsonService = new sgServicesJSON($assoc ? sgServicesJSON_LOOSE_TYPE : sgServicesJSON_IN_OBJ);
     return $jsonService->decode($json);
 }
Example #2
0
 /**
  * array-walking function for use in generating JSON-formatted name-value pairs
  *
  * @param    string  $name   name of key to use
  * @param    mixed   $value  reference to an array element to be encoded
  *
  * @return   string  JSON-formatted name-value pair, like '"name":value'
  * @access   private
  */
 function name_value($name, $value)
 {
     $encoded_value = $this->encode($value);
     if (sgServicesJSON::isError($encoded_value)) {
         return $encoded_value;
     }
     return $this->encode(strval($name)) . ':' . $encoded_value;
 }