json变换数组时中文为NULL解决方案
程序员文章站
2024-01-15 16:56:28
...
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":"张三"}';
$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":"张三"}';
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论