예제 #1
0
 /**
  * json_decode
  * 
  * @param string $encoded   源字符串
  * @param string $charset   目标字符串编码 'utf-8' or 'gb2312' or 'big5'
  * @return string/array/boolean/null
  */
 public static function jsondecode($encoded, $charset = 'utf-8')
 {
     $encoded = preg_replace(array('/([\\t\\b\\f\\n\\r ])*/s', '#^\\s*//(.+)$#m', '#^\\s*/\\*(.+)\\*/#Us', '#/\\*(.+)\\*/\\s*$#Us'), '', $encoded);
     //eat whitespace and comments
     self::$target_lang = $charset;
     $c = self::cursor($encoded);
     switch ($c) {
         case '{':
             return self::parseArray($encoded);
         case '[':
             return self::parseArray($encoded, FALSE);
         case '"':
             return self::string_find($encoded);
         case 't':
             return TRUE;
         case 'f':
             return FALSE;
         case 'n':
             return NULL;
         default:
             return self::num_read($c . $encoded);
     }
 }