代码片段如下
wx.request({
url: api.my_service_url, // 后端路径
data: that.data.request_data, // code
method: "POST",
success: function (res) {
console.log('getMyserviceData 请求成功')
wx.hideLoading();
console.log(res.data)
var resData = res.data
if(typeof resData != "object"){
log.info('getMyserviceData typeof res:',typeof resData)
var resData = JSON.parse(res.data);
}
log.info('getMyserviceData res:',resData)
log.info('getMyserviceData status:',resData.status)
log.info('getMyserviceData[status]:',resData["status"])
log.error('getMyserviceData 500 error res.data.service_list:',resData.service_list)
},
fail: function (res) {
log.error('getMyserviceData fail error:',res.data)
console.log('getMyserviceData 请求失败')
that.showInfo('内部服务错误!');
}
})
关键数据res.data的console打印如下:
{"status": 1,"totalpage": "26","service_list":[{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/17 13:13:38","content": "XXXXX"},{"group_id": "2","article_id": "376379","user_name": "XX","add_time": "2020/9/17 12:45:24","content": "XX"},{"group_id": "2","article_id": "376379","user_name": "XX","add_time": "2020/9/17 12:20:26","content": "XXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/17 12:16:35","content": "XXXXXX"},{"group_id": "2","article_id": "376379","user_name": "XX","add_time": "2020/9/17 11:42:55","content": "XXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/17 11:08:09","content": "XXXXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/17 10:12:54","content": "XXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/16 12:57:58","content": "XXXXXXXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/16 12:19:49","content": "XXXXX"},{"group_id": "2","article_id": "376379","user_name": "XX","add_time": "2020/9/15 15:46:17","content": "X"}]}
log打印日志如下:
[13:30:00] getMyserviceData res: {"status": 1,"totalpage": "26","service_list":[{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/17 13:13:38","content": "XXXXX"},{"group_id": "2","article_id": "376379","user_name": "XX","add_time": "2020/9/17 12:45:24","content": "XX"},{"group_id": "2","article_id": "376379","user_name": "XX","add_time": "2020/9/17 12:20:26","content": "XXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/17 12:16:35","content": "XXXXXX"},{"group_id": "2","article_id": "376379","user_name": "XX","add_time": "2020/9/17 11:42:55","content": "XXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/17 11:08:09","content": "XXXXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/17 10:12:54","content": "XXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/16 12:57:58","content": "XXXXXXXXX"},{"group_id": "2","article_id": "376379","user_name": "XXX","add_time": "2020/9/16 12:19:49","content": "XXXXX"},{"group_id": "2","article_id": "376379","user_name": "XX","add_time": "2020/9/15 15:46:17","content": "X"}]}
[13:30:00] getMyserviceData status: <Undefined>
[13:30:00] getMyserviceData status: <Undefined>
[13:30:00] getMyserviceData 500 error status: <Undefined>
res.data有数据,并且确实为object类型,如何解析其中的status和service_list值?