问题
调用接口打印时以为会得到该对象里的内容,得到的却是res[object Object]
console.log(“res”+res)
原因
[object Object]是对象的字符串形式,因为前面是字符串“res”,所以对象res隐式转换成字符串
解决
使用如下代码,打印出来的是对象及其属性
console.log('res',res);
补充1:json字符串和json对象的区别
这个是在控制台打印的json对象
这个是打印的json字符串
补充2:JSON.stringify()和JSON.parse()
console.log(object);
console.log(JSON.stringify(object));
//JSON.stringify()可以把 JavaScript 对象转换为字符串。
console.log(JSON.parse(JSON.stringify(object)));
//JSON.parse()将字符串转换成json对象
打印出来的效果分别是:(第一行和第二行是对象)
{companyName: null, bindNickName: null, bindAppid: null, id: 1, wxAlias: '', …}
{"companyName":null,"bindNickName":null,"bindAppid":null,"id":1,"wxAlias":"","nickName":"多客锦囊","appid":"wx663b04258fca694f","serviceType":2,"bind":false,"wxInfoId":null,"ctime":"2022-04-14 10:04:04","utime":"2022-08-01 16:43:46","dtime":null,"key":1}
{companyName: null, bindNickName: null, bindAppid: null, id: 1, wxAlias: '', …}