response中body与data的差异实例

1、this.response

{
	"url": "http://127.0.0.1:7001/api/user/list",
	"ok": true,
	"status": 200,
	"statusText": "OK",
	"headers": {
		"map": {
			"content-length": ["101"],
			"content-type": ["application/json; charset=utf-8"]
		}
	},
	"body": {
		"msg": "ok",
		"data": [{
			"id": "1",
			"name": "zhangsan",
			"sex": "male"
		}, {
			"id": "2",
			"name": "lisi",
			"sex": "male"
		}]
	},
	"bodyText": "{\"msg\":\"ok\",\"data\":[{\"id\":\"1\",\"name\":\"zhangsan\",\"sex\":\"male\"},{\"id\":\"2\",\"name\":\"lisi\",\"sex\":\"male\"}]}"
}


2、this.response.data

{
	"msg": "ok",
	"data": [{
		"id": "1",
		"name": "zhangsan",
		"sex": "male"
	}, {
		"id": "2",
		"name": "lisi",
		"sex": "male"
	}]
}


3、this.response.body

{
	"msg": "ok",
	"data": [{
		"id": "1",
		"name": "zhangsan",
		"sex": "male"
	}, {
		"id": "2",
		"name": "lisi",
		"sex": "male"
	}]
}


4、this.response.body.data

[{
	"id": "1",
	"name": "zhangsan",
	"sex": "male"
}, {
	"id": "2",
	"name": "lisi",
	"sex": "male"
}]

5、注意事项,后台返回的数据格式如下

   async list() {
        var userList = [{'id':'1', 'name':'zhangsan', 'sex':'male'},{'id':'2', 'name':'lisi', 'sex':'male'}];
        this.ctx.body = {
            msg: 'ok',
            data: userList
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值