我的后台数据返回格式为:
{
"errCode": 0,
"errMsg": "",
"data": [
{
"errCode": 0,
"errMsg": "",
"data": {
"id": 1,
"image": "http://www.ssxz.com:8096/carousel/image/01.png"
}
},
{
"errCode": 0,
"errMsg": "",
"data": {
"id": 2,
"image": "http://www.ssxz.com:8096/carousel/image/02.png"
}
}
]
}
但是wx.request接收到的数据变为了:
wx.request这样的:
wx.request({
url:'----------------------后台地址',
method:'GET',
dataType:'json',
header: {
'Content-Type': 'application/x-www-form-urlencoded',
},
success: function (res) {
if (res.data.errCode == 0) {
console.log(res)
} else {
console.log(res)
}
},
fail: function() {
console.log('网络服务失败!')
}
})
请问这个怎么解决?
把请求头改为
header:{
'Content-Type': 'application/json; charset=UTF-8', // 默认值
}