首頁 > 後端開發 > php教程 > json变换数组时中文为NULL解决方案

json变换数组时中文为NULL解决方案

WBOY
發布: 2016-06-13 12:56:50
原創
1114 人瀏覽過

json转换数组时中文为NULL解决方案
$json='[{"ZtdID":"100000","ZtdNo":"001 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"张三"},{"ZtdID":"100001","ZtdNo":"002 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"李三"}]';
var_dump(json_decode($json,true));

?>
输出为NULL
经仔细查看,是编码问题,求解?


------解决方案--------------------
iconv('gbk','UTF-8','我是中文要转换成json');

转吧.PHP的json 中文没有支持gbk gb2312的格式

------解决方案--------------------
<br />
$json='[{"ZtdID":"100000","ZtdNo":"001 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"张三"},{"ZtdID":"100001","ZtdNo":"002 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"李三"}]';<br />
debug( $json );<br />
debug( json_decode($json,true) );<br />
登入後複製

------------------输出正常
<br />
[{"ZtdID":"100000","ZtdNo":"001 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"张三"},{"ZtdID":"100001","ZtdNo":"002 ","ZtdName":"1号店 ","Address":"XX市ZZ区YY路01号铺 ","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"李三"}]<br />
<br />
Array<br />
(<br />
    [0] => Array<br />
        (<br />
            [ZtdID] => 100000<br />
            [ZtdNo] => 001 <br />
            [ZtdName] => 1号店 <br />
            [Address] => XX市ZZ区YY路01号铺 <br />
            [Remark] => <br />
            [AreaID] => 01<br />
            [ZtdTel] => 0000-8888888<br />
            [ZtdContact] => 张三<br />
        )<br />
<br />
    [1] => Array<br />
        (<br />
            [ZtdID] => 100001<br />
            [ZtdNo] => 002 <br />
            [ZtdName] => 1号店 <br />
            [Address] => XX市ZZ区YY路01号铺 <br />
            [Remark] => <br />
            [AreaID] => 01<br />
            [ZtdTel] => 0000-8888888<br />
            [ZtdContact] => 李三<br />
        )<br />
<br />
)<br />
登入後複製

------解决方案--------------------
$json='{"ZtdID":"100000","ZtdNo":"001","ZtdName":"1号店","Address":"XX市ZZ区YY路01号铺","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"张三"}';
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板