php json_decode中文乱码,Json中文乱码,该怎么解决?

用户投稿 49 0

关于“php_json_decode_乱码”的问题,小编就整理了【1】个相关介绍“php_json_decode_乱码”的解答:

Json中文乱码,该怎么解决?

解决方法:

1、把所有的中文转为UTF-8编码(本身是utf8的话无须转)

$data="JSON中文";

$newData=iconv("GB2312","UTF-8//IGNORE",$data);

2、把中文的urlencode一下

$testJSON=array('name'=>'中文字符串','value'=>'test');

//echo json_encode($testJSON);

foreach ( $testJSON as $key => $value ) {

$testJSON[$key] = urlencode ( $value );

}

3、然后json_encode之后再urldecode一下转回来

$test_json_str = json_encode ($testJSON )

echo urldecode ($test_json_str);

查看输出结果为:

{“name”:”中文字符串”,”value”:”test”}

这样可以很好的解决中文JSON乱码问题。

到此,以上就是小编对于“php_json_decode_乱码”的问题就介绍到这了,希望介绍关于“php_json_decode_乱码”的【1】点解答对大家有用。

抱歉,评论功能暂时关闭!