php处理json

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:33:36
Original
995 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:
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
Latest Issues
Return JSON from PHP script
From 1970-01-01 08:00:00
0
0
0
How to convert json string to json object in php
From 1970-01-01 08:00:00
0
0
0
Extract and access JSON data using PHP
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template