【问题标题】:JSON is showing Object rather than numerical value in outputJSON在输出中显示对象而不是数值
【发布时间】:2019-10-20 11:22:25
【问题描述】:

当我在 Chrome 中执行 URL 时,我得到以下输出:

{
  "Train_score": {
    "0": 0.9892473118
  },
  "Test_score": {
    "0": 0.9831932773
  }
}

但是,当我尝试执行以下代码以使用 Javascript 获取 JSON 时,

const fetch = require("node-fetch");

var obj

fetch(`url`)
    .then(res => res.json())
    .then(data => obj = data)
    .then(() => console.log(obj))
    .catch(err => console.error(err));

我得到以下输出: Object {Train_score: Object, Test_score: Object}.

请说明为什么它没有显示数值。我正在使用 VSCode 执行我的代码。

【问题讨论】:

标签: javascript json object visual-studio-code web-development-server


【解决方案1】:

这是预期的输出。 只需从命令行运行 node 即可获得相同的结果。

GitHub - Terminal/Output panel print '[Object]' instead of value from level-3 on within json disturbing debugging

要查看整个对象,请查看VS Code - debugging from @beniamin comment

【讨论】:

    猜你喜欢
    • 2014-10-02
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    相关资源
    最近更新 更多