ResponseJson.php
<?php /** * Created by PhpStorm. * User: czg * Date: 2016/12/8 * Time: 18:28 */ class ResponseJson { /** * 按json方式输出通信数据 * @param integer $code 状态码 如200、400等 * @param string $message 提示信息 * @param array $data 数据 * return string */ public static function json($code, $message = "", $data = array()) { if (!is_numeric($code)) { return ""; } $result = array( 'code' => $code, 'message' => $message, 'data' => $data ); echo json_encode($result); } } CallResonseJson.php 调用例子
<?php /** * Created by PhpStorm. * User: chendd * Date: 2016/12/9 * Time: 10:49 */ require_once("../../AppApi/ResponseJson.php"); //===========例子1 //$arr = array( // "id"=>1, // "name" =>"caizhigui" //); // //ResponseJson::json(200,'数据返回成功',$arr); //===========例子2 $ar = array( "auth" => array( "user" => "customer", "password" => "password", "context" => "4", ), "owner" => array( "user" => "customer2", "context" => "4", ), "language" => "en", "task" => array( "code" => "0130", ), ); ResponseJson::json(200,'数据返回成功',$ar);