php处理json

WBOY
WBOYOriginal
2016-06-23 14:33:36971browse

解决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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:[zz]PHP 正则Next article:PHP implode() 函数