当前位置:Gxlcms > PHP教程 > json变换数组时中文为NULL解决方案

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

时间:2021-07-01 10:21:17 帮助过:10人阅读

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的格式

------解决方案--------------------

$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":"李三"}]';
debug( $json );
debug( json_decode($json,true) );

------------------输出正常

[{"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":"李三"}]

Array
(
[0] => Array
(
[ZtdID] => 100000
[ZtdNo] => 001
[ZtdName] => 1号店
[Address] => XX市ZZ区YY路01号铺
[Remark] =>
[AreaID] => 01
[ZtdTel] => 0000-8888888
[ZtdContact] => 张三
)

[1] => Array
(
[ZtdID] => 100001
[ZtdNo] => 002
[ZtdName] => 1号店
[Address] => XX市ZZ区YY路01号铺
[Remark] =>
[AreaID] => 01
[ZtdTel] => 0000-8888888
[ZtdContact] => 李三
)

)

------解决方案--------------------
$json='{"ZtdID":"100000","ZtdNo":"001","ZtdName":"1号店","Address":"XX市ZZ区YY路01号铺","Remark":"","AreaID":"01","ZtdTel":"0000-8888888","ZtdContact":"张三"}';

人气教程排行