当前位置: 代码迷 >> PHP >> 返回JSON数据的接口解决方案
  详细解决方案

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

热度:62   发布时间:2016-04-28 19:40:22.0
返回JSON数据的接口
需要写一个只给出连接就可以返回JSON数据的接口 如何实现 请给出思路
------解决方案--------------------
http://sxxxxx/json.php?type=1
http://sxxxxx/json.php?type=2


header('Content-type: application/json');
$type = isset($_GET['type']) ? intval($_GET['type']) : 1;

$array = array();
if ($type == 1) {
  $array = array("test" => "I'm 1");
} else if ($type == 2) {
  $array = array("test" => "I'm 2");
}

echo json_encode($array);
  相关解决方案