【问题标题】:Why are some JSON attributes omitted?为什么省略了一些 JSON 属性?
【发布时间】:2016-11-29 07:23:00
【问题描述】:

我有一个我正在使用的 JSON 对象。这是 HTTP GET 请求的结果。

预期结果如下:

{
  "name": {
    "type": "string"
  },
  "authors": {
    "collection": "users",
    "via": "IDPid"
  },
  "id": {
    "type": "integer",
    "autoIncrement": true,
    "primaryKey": true,
    "unique": true
  }
}

实际结果如下(省略authors属性):

{
  "name": {
    "type": "string"
  },
  "id": {
    "type": "integer",
    "autoIncrement": true,
    "primaryKey": true,
    "unique": true
  }
}

为什么去掉了 authors 属性?

但是,当我在 Chrome 中调试它时,虽然 authors 属性仍然被省略,但我能够执行 console.log(response.authors) 并且它读取它很好。

另外,当我转到 Chrome 开发工具上的“网络”选项卡查看 HTTP 请求的响应时,它会在响应正文中显示缺少的属性。

【问题讨论】:

  • 你能给我们一个工作的例子吗?或者至少告诉我们您是如何查看“实际”结果的?
  • 你在哪里看到没有作者属性的 json 数据?网络选项卡会逐字向您显示收到的数据。这就是响应您的 GET 请求而返回的内容。

标签: javascript json google-chrome-devtools


【解决方案1】:

我发现了问题。这是因为console.log 没有立即运行。它会在一段时间后运行。我有其他代码修改了该对象,但由于某种原因,console.log 在该代码之后运行,即使我之前编写过它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 2018-09-29
    • 2022-01-16
    • 1970-01-01
    • 2018-02-04
    相关资源
    最近更新 更多