php处理json

WBOY
Release: 2016-06-23 14:33:36
Original
973 people have browsed it

解决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 ) );	?>
Copy after login

foreach 是复制遍历,如果想在原数组上修改:

foreach ($json1 as &$value){$value['name'] = urlencode( $value['name']);}
Copy after login

 

 对于json数据ajax到前台的时候不会有乱码。 因为ajax本身自动转成utf8

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template