Home  >  Article  >  Backend Development  >  PHP generates JSON

PHP generates JSON

不言
不言Original
2018-06-04 10:14:571500browse

This article mainly introduces the generation of JSON by PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

<?php
$arr = array(
	&#39;id&#39;=>1,
	&#39;name&#39;=>&#39;andros230&#39;
);

$result = array(
	&#39;code&#39;=>&#39;200&#39;,
	&#39;msg&#39;=>&#39;成功&#39;,
	&#39;data&#39;=>$arr
		);
echo json_encode($result,JSON_UNESCAPED_UNICODE);

?>

Output: {"code":" 200","msg":"success","data":{"id":1,"name":"andros230"}}

Note: JSON_UNESCAPED_UNICODE requires PHP5 to solve Chinese garbled characters. Version 4 or above

Related recommendations:

php generates csv file

The above is the detailed content of PHP generates JSON. For more information, please follow other related articles on the PHP Chinese website!

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