json encode中文unicode的問題

2021-07-11 09:38:34 字數 890 閱讀 3341

$a = array('str1' => '中文', 'str2' => 'english');                                  

var_dump(json_encode($a));

//string(40) ""

解決方法如下:

把漢字先 urlencode 然後再使用json_encode,json_encode之後再次使用urldecode 來解碼,這樣編碼出來的json陣列中的漢字就不會出現unicode編碼了。

$a = array('str1' => urlencode('中文'), 'str2' => 'english');                       

var_dump(urldecode(json_encode($a)));

//string(34) ""

function get_array($arrresult,$arr=array())else }

return $arr; }

//$menuarr是乙個多維陣列

$post=urldecode (json_encode(get_array($menuarr)));

php 5.4中對json_encode對options可選引數增加 json_unescaped_unicode常量,即不編碼為unicode

$a = array('str1' => '中文', 'str2' => 'english');   

var_dump(json_encode($a, json_unescaped_unicode));

//string(34) ""

json encode 處理中文

將php物件轉為json資料 arr array 1,2,hello json array name 國哥 男 jsonarr json encode arr 將json資料解析為php物件 arr json decode jsonarr 當資料存在中文轉為json格式的時候中文轉為unicode值...

json encode 中文處理

在 php 中使用 json encode 內建函式 php 5.2 可以使用得 php 中資料可以與其它語言很好的傳遞並且使用它。這個函式的功能是將數值轉換成json資料儲存格式。arr array name 希亞 age 20 jsonencode json encode arr echo js...

解決 json encode 中文亂碼

解決以下問題 json encode 中文後的字串不可閱讀 json encode 多級陣列中文亂碼問題 json encode 陣列中包含換行時錯誤問題 json encode 陣列中鍵為中文的問題 php function encode arr return addcslashes urldec...