gpt4 book ai didi

javascript - 来自 Axios 的响应数据将我的 JSON 转换为 Object 对象

转载 作者:行者123 更新时间:2023-12-04 09:43:16 25 4
gpt4 key购买 nike

我正在尝试使用 Axios 从后端发出请求,这是请求的数据

[
{
"_id": "5ed99cd7972ceb1e203ff3d4",
"model": "76 Runer Nylonmedieval Blue-grey Violet ",
"code": "352077-14",
"brand": "PUMA",
"description": "Corres mucho",
"value": 119000,
"size": 11,
"stock": 50,
"date": "2020-06-05T01:14:17.000Z",
"image": "upload\\352077-14.jpg",
"total": 714000
},
{
"_id": "5edc01f0efed972e1c13c76e",
"model": "Force",
"code": "200-1142",
"brand": "Reebok",
"description": "Perfectos para realizar crossfit, con dos agarres laterales perfectos para Rope Climbing",
"value": 310000,
"size": 45,
"stock": 20,
"date": "2020-06-06T20:50:44.000Z",
"image": "upload\\Screenshot_8.png",
"total": 1240000
},
{
"_id": "5edc0163efed972e1c13c76c",
"model": "Elegant",
"code": "2002-1",
"brand": "Velez",
"description": "comodos y perfectos para ocasiones especiales ",
"value": 340000,
"size": 41,
"stock": 13,
"date": "2020-06-06T20:48:26.000Z",
"image": "upload\\Screenshot_1.png",
"total": 680000
}
]

但是当我尝试在我的页面中对其进行 console.log 时,我只是得到响应“data [object Object],[object Object],[object Object]”,所以我不能使用任何 json 数据。这是前端的 axios 请求:

axios.get('http://localhost:5000/users/carProducts/'+ID.userid)
.then(res =>{
console.log('data '+res.data)
})
.catch(error => console.log(error));

最佳答案

您正在完美地获取数据。问题是您记录的错误

当您将字符串与对象连接时,输出如下所示 data [object Object],[object Object],[object Object]

尝试将数据作为参数传递。你会看到数据

 console.log('data ',res.data)

let data={'name':'trevor'}
console.log("Details"+data)
console.log("Difference")
console.log("Details",data)

关于javascript - 来自 Axios 的响应数据将我的 JSON 转换为 Object 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62239941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com