api json
<?php
class Response
{
/**
* @param integer $code 状态码
* @param string $message 提示信息
* @param array $data 数据
*/
public static function json($code, $message = '', $data = array())
{
if(!is_numeric($code)){
return "";
}else{
$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);
echo json_encode($result);
exit;
}
}
}
?>
<?php
require_once "response.php";
$arr=array(
'id'=>1,
'name'=>'singwa'
);
Response::json(200,'数据组装成功!',$arr);