大家经常会遇到使用json_encode转成json格式时,中文会变成urlencode格式:\u9017\u6bd4\u8bfa\u59d0.
现在提供一种解决方法:
在json_encode之前使用urlencode转一下,然后返回的数据json_decode后再使用urldecode转回来
例子:
<?php
$testJSON=array('name'=>'中文字符串','value'=>'test');
//echo json_encode($testJSON);
foreach ( $testJSON as $key => $value ) {
$testJSON[$key] = urlencode ( $value );
}
echo urldecode ( json_encode ( $testJSON ) );
?>