首頁 >後端開發 >php教程 >GBK的页面输出JSON格式的php函数_PHP教程

GBK的页面输出JSON格式的php函数_PHP教程

WBOY
WBOY原創
2016-07-21 15:40:56808瀏覽

复制代码 代码如下:

function tb_json_encode($value, $options = 0)
{
return json_encode(tb_json_convert_encoding($value, “GBK”, “UTF-8″));
}

function tb_json_decode($str, $assoc = false, $depth = 512)
{
return tb_json_convert_encoding(json_decode($str, $assoc), “UTF-8″, “GBK”);
}

function tb_json_convert_encoding($m, $from, $to)
{
switch(gettype($m)) {
case ‘integer':
case ‘boolean':
case ‘float':
case ‘double':
case ‘NULL':
return $m;

case 'string':
return mb_convert_encoding($m, $to, $from);
case ‘object':
$vars = array_keys(get_object_vars($m));
foreach($vars as $key) {
$m->$key = tb_json_convert_encoding($m->$key, $from ,$to);
}
return $m;
case ‘array':
foreach($m as $k => $v) {
$m[tb_json_convert_encoding($k, $from, $to)] = tb_json_convert_encoding($v, $from, $to);
}
return $m;
default:
}
return $m;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/321266.htmlTechArticle复制代码 代码如下: function tb_json_encode($value, $options = 0) { return json_encode(tb_json_convert_encoding($value, “GBK”, “UTF-8″)); } function tb_json_decode($...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn