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

WBOY
Release: 2016-06-13 11:50:00
Original
942 people have browsed it

返回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 />
Copy after login

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!