当前位置: 代码迷 >> JavaScript >> PHP函数json_encode汉语乱码解决
  详细解决方案

PHP函数json_encode汉语乱码解决

热度:183   发布时间:2013-11-09 17:06:34.0
PHP函数json_encode中文乱码解决
http://www.cotrun.net/blog/1052.html

<?php

$data = array(
‘game’ => ‘冰火国度’,
‘name’ =>  ‘刺之灵’,
‘country’ => ‘冰霜国’,
‘level’ => 45
);
echo json_encode( $data );
echo ‘<br>’;
/**
* 处理json_encode乱码
*/
$newData = array();
foreach( $data as $key => $value )
{
$newData[ $key ] = urlencode( $value );
}
echo urldecode( json_encode( $newData ) );
?>