console.log()打印对象得到[object Object]

您所在的位置:网站首页 vue打印对象 console.log()打印对象得到[object Object]

console.log()打印对象得到[object Object]

2023-10-04 05:27| 来源: 网络整理| 查看: 265

问题

调用接口打印时以为会得到该对象里的内容,得到的却是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: '', …}


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3