Heim > Artikel > Backend-Entwicklung > php处理json
解决php页面的json数据中文乱码
<?php $json = array ( 0 => array ( 'id' => '13', 'name' => '乒乓球', ), 1 => array ( 'id' => '17', 'name' => '篮球', ) ) ?> <?php $newData = array(); foreach( $json as $key => $value ) { $newData[$key]['name'] = urlencode( $value['name']); } echo urldecode( json_encode( $newData ) ); ?>
foreach 是复制遍历,如果想在原数组上修改:
foreach ($json1 as &$value){$value['name'] = urlencode( $value['name']);}
对于json数据ajax到前台的时候不会有乱码。 因为ajax本身自动转成utf8