范例
1、基本的返回格式(必要字段及说明)
{
"code": "", // 业务返回码
"data": {}, // 数据内容
"message_type": "", // 消息文本类型,可选值:none(无消息内容);info(正常)、warn(警告)、error(错误)、success(成功)
"message": "" // 消息文本内容
}
C# 项目也可采用驼峰写法(如果可能,建议使用上面的方式):
{
"code": "",
"data": {},
"messageType": "",
"message": ""
}
2、返回单条数据结构
{
"code": "1001010",
"data": {
"id": "985123a0-7e4f-11e7-9022-fb7190c856e4",
...
},
"message_type": "info",
"message": "哈哈哈"
}
3、返回带分页的列表数据结构
状态一:无数据
{
"code": "1001010",
"data": {
"list": [],
"total": 0, // 数据总(条)数
"current": 1, // 当前页数
"page_size": 10 // 每页条数
},
"statistics": {
"total": 0
},
"message_type": "info",
"message": "哈哈哈"
}
状态二:有一条数据
{
"code": "1001010",
"data": {
"list": [{
"id": "985123a0-7e4f-11e7-9022-fb7190c856e4",
...
}],
"total": 0,
"current": 1,
"page_size": 10
},
"statistics": {
"total": 0
},
"message_type": "info",
"message": "哈哈哈"
}
状态三:有多条数据
{
"code": "1001010",
"data": {
"list": [{
"id": "985123a0-7e4f-11e7-9022-fb7190c856e4",
...
}, {
"id": "df7cca36-3d7a-40f4-8f06-ae03cc22f045",
...
}],
"total": 0,
"current": 1,
"page_size": 10
},
"statistics": {
"total": 0
},
"message_type": "info",
"message": "哈哈哈"
}
4、返回带统计信息的列表数据结构
状态一:无数据
{
"code": "1001010",
"data": {
"list": []
},
"statistics": {
"total": 0
},
"message_type": "info",
"message": "哈哈哈"
}
状态二:有数据,有统计信息
{
"code": "1001010",
"data": {
"list": [{
"id": "985123a0-7e4f-11e7-9022-fb7190c856e4",
...
}, {
"id": "df7cca36-3d7a-40f4-8f06-ae03cc22f045",
...
}]
},
"statistics": {
"total": 2
},
"message_type": "info",
"message": "哈哈哈"
}