Home > Backend Development > PHP Tutorial > How do you generally standardize the content returned by the interface?

How do you generally standardize the content returned by the interface?

WBOY
Release: 2016-09-14 09:41:23
Original
1646 people have browsed it

Generally, the contents returned by the backend include return codes, arrays, and prompt information.
How do you usually name them?
Also, the entire returned array json is generally once, or is it more than one layer of json?

Reply content:

Generally, the contents returned by the backend include return codes, arrays, and prompt information.

How do you usually name them?
Also, the entire returned array json is generally once, or is it more than one layer of json?

Reference is as follows

<code>{
    Status: 1, //数据状态
    Code: 200, //反码状态
    Message: 'Successful', //描述信息
    ClientTime: 1473765898, //客户端请求时间
    ServerTime: 1473765935, //服务端响应时间
    token: '38ce6474a370c3fe84ddf92403bec204cfcbe07b', //唯一token也可做加密key
    data:{ //json数据,格式层级关系根据对应需求虽易定
        key1: value1,
        key2: value2,
        key3: {
        [
            name: '小明',
            sex: 1,
        ],[
            name: '小华',
            sex: 1,
        ],[
            name: '小刚',
            sex: 1,
        ]}
    }
}</code>
Copy after login

<code>errNo=>
errMsg=>
data=></code>
Copy after login
Then json_encode this array

<code>{
    code:200,
    message: "success",
    data: { key1: value1, key2: value2, ... }
}</code>
Copy after login
code: error code

message: description information, "success" when successful, error message when error occurs

data: data returned when successful, type is object or array

When successful:

<code class="json">{
    "code":“200”,
    "data":“成功返回数据,如果没有数据返回空数组形式[]”
}</code>
Copy after login

When an error occurs:

<code class="json">{
    "code":"错误码",
    "msg":"错误提示"
}</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template