输出json格式的内容
@param  mixed $arr 要输出的内容
@param  boolean $out 是否输出 默认为true 设置为false的时候返回编码好的数据
@return string
501579
public function json($arr, $out = true)
    {
        $this->setHeader('Content-type', 'application/json');
        $res = json_encode($arr, JSON_UNESCAPED_UNICODE);
        if ($out) {
            $this->send($res);
            return "";
        }
        return $res;
    }
568641
public function urlencode_array(array $ar) {
		$datastring = '';
		foreach ($ar as $key => $val) {
			if (!empty($datastring)) {
				$datastring .= '&';
			}
			$datastring .= urlencode($key).'='.urlencode($val);
		}
		return $datastring;
	}
173291
public static function fromUnicode($arr)
    {
        ob_start();

        foreach (array_keys($arr) as $k) {
            # ASCII range (including control chars)
            if (($arr[$k] >= 0) && ($arr[$k] <= 0x007f)) {
                echo chr($arr[$k]);
                # 2 byte sequence
            } else {
                if ($arr[$k] <= 0x07ff) {
                    echo chr(0xc0 | ($arr[$k] >> 6));
                    echo chr(0x80 | ($arr[$k] & 0x003f));
                    # Byte order mark (skip)
                } else {
                    if ($arr[$k] == 0xFEFF) {
                        // nop -- zap the BOM

                        # Test for illegal surrogates
                    } else {
                        if ($arr[$k] >= 0xD800 && $arr[$k] <= 0xDFFF) {
                            // found a surrogate
                            trigger_error(
                                'utf8_from_unicode: Illegal surrogate ' .
                                'at index: ' . $k . ', value: ' . $arr[$k],
                                E_USER_WARNING
                            );

                            return false;
                            # 3 byte sequence
                        } else {
                            if ($arr[$k] <= 0xffff) {
                                echo chr(0xe0 | ($arr[$k] >> 12));
                                echo chr(0x80 | (($arr[$k] >> 6) & 0x003f));
                                echo chr(0x80 | ($arr[$k] & 0x003f));
                                # 4 byte sequence
                            } else {
                                if ($arr[$k] <= 0x10ffff) {
                                    echo chr(0xf0 | ($arr[$k] >> 18));
                                    echo chr(0x80 | (($arr[$k] >> 12) & 0x3f));
                                    echo chr(0x80 | (($arr[$k] >> 6) & 0x3f));
                                    echo chr(0x80 | ($arr[$k] & 0x3f));
                                } else {
                                    trigger_error(
                                        'utf8_from_unicode: Codepoint out of Unicode range ' .
                                        'at index: ' . $k . ', value: ' . $arr[$k],
                                        E_USER_WARNING
                                    );

                                    // out of range
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }

        $result = ob_get_contents();
        ob_end_clean();

        return $result;
    }
257974
public static function toJson(array $array, bool $prettyPrint = true, bool $unescapedSlashes = true): string
    {
        $options = 0;
        if ($unescapedSlashes) {
            $options += JSON_UNESCAPED_SLASHES;
        }
        if ($prettyPrint) {
            $options += JSON_PRETTY_PRINT;
        }
        return json_encode($array, $options);
    }
269161
static function stringContainsWord($str, array $arr)
    {
        foreach($arr as $a) {
            if (stripos($str,$a) !== false) return true;
        }
        return false;
    }
810200
public static function gbk2utf8($str, $outCode = 'UTF-8') {
		if (self::isUtf8String($str) == false) {
			return iconv('GBK', $outCode, $str);
		}
		return $str;
	}
467797
public function smartOutput(...$args) {
        if (count($args) === 1 && is_array($args[0])) {
            $code = $args[0]['code'] ?? 0;
            $message = $args[0]['message'] ?? null;
            $data = $args[0]['data'] ?? null;
            $goto = $args[0]['goto'] ?? null;
            $tpl = $args[0]['tpl'] ?? null;
        } else {
            $code = $args[0] ?? 0;
            $message = $args[1] ?? null;
            $data = $args[2] ?? null;
            $goto = $args[3] ?? null;
            $tpl = $args[4] ?? null;
        }
        if ($this->is_ajax || $this->json_expected) {
            X::logger()->trace('Output JSON');
            $this->jsonError($code, $message, $data, $goto);
        } else {
            if (!empty($goto)) {
                X::logger()->trace("Redirect to $goto");
                $this->redirect($goto);
            } else {
                if (null !== $message && !isset($data['message'])) {
                    $data['message'] = $message;
                }
                if ($tpl) {
                    X::logger()->trace("Display with tpl $tpl");
                    $this->display($tpl, $data);
                } else {
                    X::logger()->trace('Display');
                    $this->display($data);
                }
            }
        }
        return $this;
    }
1319868
protected function _deflate($arr)
	{
		if (is_string($arr))
		{
			$arr = htmlentities($arr, ENT_COMPAT, 'UTF-8');
			$arr = preg_replace('/\[(.+?)\] =&gt;/i', '<code class="ky">[$1]</code> <code class="op">=></code>', $arr);
			return $arr;
		}

		$output = 'Array( ' . "\n";
		$a = array();
		if (is_array($arr))
		{
			foreach ($arr as $key => $val)
			{
				if (is_array($val))
				{
					$a[] = "\t" . '<code class="ky">' . $key . '</code> <code class="op">=></code> <code class="vl">' . $this->_deflate($val) . '</code>';
				}
				else
				{
					$val = htmlentities($val, ENT_COMPAT, 'UTF-8');
					$val = preg_replace('/\[(.+?)\] =&gt;/i', '<code class="ky">[$1]</code> <code class="op">=></code>', $val);
					$a[] = "\t" . '<code class="ky">' . $key . '</code> <code class="op">=></code> <code class="vl">' . $val . '</code>';
				}
			}
		}
		$output .= implode(", \n", $a) . "\n" . ' )' . "\n";

		return $output;
	}
444462
private static function unicodeToUtf8($arr) {
    $dest = '';
    foreach ($arr as $src) {
      $dest .= self::utf8($src);
    }
    return $dest;
  }
1013828
protected function _json_encode($arg)
    {
        /*
         * This function is very similar to json_encode, however it will traverse array
         * before encoding in search of jsExpressionable objects. Those would
         * be replaced with their jsRendering.
         */
        if (is_object($arg)) {
            if ($arg instanceof jsExpressionable) {
                $result = $arg->jsRender();

                return $result;
            } else {
                throw new Exception(['Not sure how to represent this object in JSON', 'obj' => $arg]);
            }
        } elseif (is_array($arg)) {
            $array = [];
            // is array associative? (hash)
            $assoc = $arg != array_values($arg);

            foreach ($arg as $key => $value) {
                $value = $this->_json_encode($value);
                $key = $this->_json_encode($key);
                if (!$assoc) {
                    $array[] = $value;
                } else {
                    $array[] = $key.':'.$value;
                }
            }

            if ($assoc) {
                $string = '{'.implode(',', $array).'}';
            } else {
                $string = '['.implode(',', $array).']';
            }
        } elseif (is_string($arg)) {
            $string = '"'.$this->_safe_js_string($arg).'"';
        } elseif (is_bool($arg)) {
            $string = json_encode($arg);
        } elseif (is_numeric($arg)) {
            $string = json_encode($arg);
        } elseif (is_null($arg)) {
            $string = json_encode($arg);
        } else {
            throw new Exception(['Unable to json_encode value - unknown type', 'arg' => var_export($arg, true)]);
        }

        return $string;
    }
1317715
public static function Deserialize($arr){
		if(is_null($arr))
			return null;
		$res=Array();
		$i=-1;
		$len=sizeof($arr);
		while(++$i<$len)
			$res[$arr[$i]->Key]=$arr[$i]->Value;
		return $res;
	}
827633
public function json($asArray = false)
    {
        $json = json_decode((string) $this->getBody(), $asArray);
        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new RuntimeException(sprintf("The response is not a valid json: %s", json_last_error_msg()));
        }

        return $json;
    }
257209
protected static function strContains($str, array $arr)
    {
        foreach ($arr as $a) {
            if (stripos($str, $a) !== false) {
                return true;
            }
        }
        return false;
    }
273873
public function out($str, $opt = array())
    {
        $data = array_merge($opt, ['text' => rtrim($str, "\n")]);
        //if($color)$data['style']='color: '.$color;
        $this->sseMessageJSON($data);
    }
1109070
public function serialize($resource, OutputStream $out): OutputStream
    {
        if (is_scalar($resource) || $resource instanceof Error) {
            $out->writeLine((string) $resource);
        } elseif (is_array($resource) || $resource instanceof \Traversable) {
            $this->serializeIterable($resource, $out);
        } elseif (is_object($resource)) {
            $this->serializeIterable(castToArray($resource), $out);
        } else {
            trigger_error(
                    'Resource of type ' . typeOf($resource)
                    . ' can not be serialized to csv',
                    E_USER_ERROR
            );
        }

        return $out;
    }
245339
public static function arr2json($data)
    {
        $json = json_encode(self::buildEnEmojiData($data), JSON_UNESCAPED_UNICODE);
        return $json === '[]' ? '{}' : $json;
    }
1164599
public static function json($var, $continue = false, $hide = false, $return = false){
        $Stop = new \Stop\Dumper\Json($hide, $continue, $return, Dumper\AbstractDumper::FORMAT_JSON);
        $Stop->var_dump($var);
    }