首页 > 解决方案 > 作为 [object Object] 进入服务器的对象数组

问题描述

我正在尝试将当前状态的属性作为(对象数组)发送到我的服务器。当我尝试将它记录到我的服务器中时,它作为 [object Object] 的数组返回。JSON.stringify 仅在每个对象周围添加“”。

//sending my current players property to here
getFantasyPros: function(players) {
    return axios.get("/api/scraper/" + players);
  },

//end point
router.get("/:players", (req, res) => {
    const playerArr = JSON.stringify(req.params);
    console.log(playerArr);
}

标签: javascriptaxios

解决方案


您需要通过您的回复(res)返回一些东西。添加到端点的末尾。

return res.json({
  playerArr,
  msg: 'It worked'
})

推荐阅读