res.data 中的单个元素取值 undefined
发布于 5 年前 作者 jiehao 9049 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

确认 返回值是 JSON 的格式,  console.log(res.data.Id); 输出是undefined     console.log(res.data);这个就一点问题没有  请教一下  是什么个问题

load: function (e) {//根据名字 密码 微信唯一id 第一次登陆先确认有没有这个人,然后再修改后台 微信唯一id 以后根据唯一id确认登陆

var that = this;

var msg = “”;

wx.request({

url: ’  ',

data:{

//  Mainid: mainid,

LoadName:this.data.name,

LoadNum: this.data.serect,

},

header: {

//  ‘content-type’: ‘application/x-www-form-urlencoded’  //这里注意POST请求content-type是小写,大写会报错   .

‘content-type’: ‘application/json’ // 默认值

},

method: ‘get’,

dataType:‘json’  ,

success: function (res) {

console.log(res.data);

console.log(res.data.Id);

//console.log(JSON.parse(res.data));

msg = res.data;

// console.log(JSON.stringify(res.data));

// console.log(msg.Id);

//console.log(JSON.parse(res.data));

that.setData({

logs: msg ,

})       ;

},

fail: function ( res) {

console.log(err)

},

})

// console.log(logs.Id);

},

3 回复

我也碰到这个问题!!!!

你们的解决了吗 我这也出现这种情况 大部分情况下请求的返回值都是json 偶尔会返回字符串 content-type设置的也没错 不知道咋回事

应该是json字符串格式,如果是正确的json格式不会取不到值

回到顶部