sarju/json_response

一个简单的类,用于返回格式正确的json响应

1.1.1 2022-12-16 11:47 UTC

This package is auto-updated.

Last update: 2024-09-16 15:27:48 UTC


README

一个简单的类,用于返回格式正确的json响应

安装

composer require sarju/json_response

使用方法

<?php

require_once __DIR__ . "/vendor/autoload.php";

use Devscreencast\ResponseClass\JsonResponse;

$student = array(
    'name' => 'John Doe',
    'course' => 'Software Engineering',
    'level' => '200',
    'collections' => ['books' => 'Intro to UML', 'music' => 'rap']
);

new JsonResponse('unauthorized', '', $student);

Param1 (必需)

  1. success 或 ok - 200 http 状态码
  2. unauthorized - 401 http 状态码
  3. exception - 500 http 状态码(内部服务器错误)

Param2 (可选)

字符串 - 返回的消息,如果不可用,请使用空引号

Param3 (可选)

数组 - 数据数组