header("Content-Type:text/html;charset=utf-8;");
$arr = array (Version_code=>2,Version_name=>UpdateVersion,Versoin_desc=>更新了地图功能,Versoin_path=>/BusIot/APK/BusIot.apk);
echo json_encode($arr);
?>
如上代码,即为将字符串变量转化成json格式输出,但是输出结果如下:
{"Version_code":2,"Version_name":"UpdateVersion","Versoin_desc":"\u66f4\u65b0\u4e86\u5730\u56fe\u529f\u80fd","Versoin_path":"http:\/\/\/BusIot\/APK\/BusIot.apk"}
即数组中所有中文在json_encode之后都不见了或者出现\u2353等。
解决方法是用urlencode()函数处理以下,在json_encode之前,把所有数组内所有内容都用urlencode()处理一下,然用json_encode()转换成json字符串,最后再用urldecode()将编码过的中文转回来。
header("Content-Type:text/html;charset=utf-8;");
$arr = array (