Home >Backend Development >PHP Tutorial >How do you generally standardize the content returned by the interface?
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?
How do you usually name them?
Also, the entire returned array json is generally once, or is it more than one layer of json?
<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>
<code>errNo=> errMsg=> data=></code>Then json_encode this array
<code>{ code:200, message: "success", data: { key1: value1, key2: value2, ... } }</code>code: error code
message: description information, "success" when successful, error message when error occurs
data: data returned when successful, type is object or array
<code class="json">{ "code":“200”, "data":“成功返回数据,如果没有数据返回空数组形式[]” }</code>
<code class="json">{ "code":"错误码", "msg":"错误提示" }</code>