首页 > Other > json_encode转换中文为null的问题

json_encode转换中文为null的问题

把要转换的数组先urlencode一下就好了,json化后再urldecode下。 <?php

$data = array(
'game' => '冰火国度',
'name' => '刺之灵',
'country' => '冰霜国',
'level' => 45
);

/**
* 处理json_encode乱码
*/
$newData = array();
foreach( $data as $key => $value )
{
$newData[ $key ] = urlencode( $value );
}
echo urldecode( json_encode( $newData ) );

?>

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: