Example #1
0
 /**
  *
  * Encodes the mixed $valueToEncode into JSON format.
  *
  * @param mixed $valueToEncode Value to be encoded into JSON format
  *
  * @param array $deQuote Array of keys whose values should **not** be
  * quoted in encoded string.
  *
  * @param bool $forceObject force all arrays to objects
  *
  * @return string JSON encoded value
  *
  */
 public function encode($valueToEncode, $deQuote = array(), $forceObject = false)
 {
     mb_internal_encoding('ASCII');
     if (!$this->_config['bypass_ext'] && function_exists('json_encode') && defined('JSON_FORCE_OBJECT')) {
         if ($this->_config['noerror']) {
             $old_errlevel = error_reporting(E_ERROR ^ E_WARNING);
         }
         $encoded = json_encode($valueToEncode, $forceObject ? JSON_FORCE_OBJECT : null);
         if ($this->_config['noerror']) {
             error_reporting($old_errlevel);
         }
     } else {
         // fall back to php-only method
         self::$forceObject = $forceObject ? true : null;
         $encoded = $this->_json_encode($valueToEncode);
     }
     // sometimes you just don't want some values quoted
     if (!empty($deQuote)) {
         $encoded = $this->_deQuote($encoded, $deQuote);
     }
     mb_internal_encoding('UTF-8');
     return $encoded;
 }