function jsons($code, $message = ‘‘, $data = array()) { if(!is_numeric($code)) { return ‘‘; } $result = array( ‘code‘ => $code, ‘message‘ => urlencode($message), ‘data‘ => $data ); echo urldecode(json_encode($result,JSON_UNESCAPED_UNICODE)); exit; }
控制器的写法:
return jsons(1,‘返回数据成功!‘,$data);exit;
效果: