Home  >  Article  >  Backend Development  >  返回JSON数据的接口解决方案

返回JSON数据的接口解决方案

WBOY
WBOYOriginal
2016-06-13 11:50:00943browse

返回JSON数据的接口
需要写一个只给出连接就可以返回JSON数据的接口 如何实现 请给出思路
------解决方案--------------------
http://sxxxxx/json.php?type=1
http://sxxxxx/json.php?type=2

<br />header('Content-type: application/json');<br />$type = isset($_GET['type']) ? intval($_GET['type']) : 1;<br /><br />$array = array();<br />if ($type == 1) {<br />  $array = array("test" => "I'm 1");<br />} else if ($type == 2) {<br />  $array = array("test" => "I'm 2");<br />}<br /><br />echo json_encode($array);<br />

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