php将数组转为json涌现中文乱码的处理方法:首先将数组中的每一个元素举行urlenconde()转码;然后再运用json_encode()函数把每一个元素转为json即可。
处理思绪:
(引荐教程:php视频教程)
为数组里的每一个元素举行urlencode()转码,然后再用json_encode()转为json即可。解码运用json_decode()。
举例:
foreach ( $result as $keys => $value )
//包括中文的二维数组$result转json,数组内部元素逐一运用urlencode转换即可保证中文不乱码
{
foreach($value as $key=>$column){
$testJSON[$keys][$key] = urlencode ( $column );
}
}
var_dump( json_encode ( $testJSON ));//转为json
$result = urldecode ( json_encode ( $testJSON ) );//转回数组
更多相干学问请接见php培训。
以上就是php将数组转为json涌现中文乱码怎么办的细致内容,更多请关注ki4网别的相干文章!
收藏 | 0