【问题标题】:Trouble accessing JSON array访问 JSON 数组时遇到问题
【发布时间】:2015-02-21 19:30:44
【问题描述】:

数据如下:

[
  {
    "passports": [
      {
        "identifier": "2238006043",
        "protocol": "oauth",
        "tokens": {
          "token": "2238006043-fACsU7gVtpZnkuerodfsfdsfsdfdffsfOck1R9Z",
          "tokenSecret": "BQN25aRkJcyES3yWFCa7sSpq212PKbB52Mplxpg58hICs"
        },
        "provider": "twitter",
        "user": "54e8bca1513ab1841ab6da01",
        "createdAt": "2015-02-21T17:13:05.371Z",
        "updatedAt": "2015-02-21T17:13:05.371Z",
        "id": "54e8bca1513ab1841ab6da02"
      }
    ],
    "username": "myUsername",
    "createdAt": "2015-02-21T17:13:05.362Z",
    "updatedAt": "2015-02-21T17:13:05.362Z",
    "id": "54e8bca1513ab1841ab6da01"
  },

我正在尝试从护照中输出如下内容:

console.log(util.inspect(res.passports[0].identifier, { showHidden: true, depth: null }));

res 是包含如下数据的 JSON 对象。

【问题讨论】:

  • res[0].passports[0]... 也许

标签: javascript json node.js sails.js


【解决方案1】:

试试

console.log(util.inspect(res[0].passports[0].identifier, { showHidden: true, depth: null }));

看起来res 是一个数组

【讨论】:

    【解决方案2】:

    res JSON 对象包含一个项目列表。这就是为什么它没有给出任何价值。 请试试这个。

    console.log(util.inspect(res[0].passports[0].identifier, { showHidden: true, depth: null }));
    

    【讨论】:

      猜你喜欢
      • 2020-10-25
      • 2023-03-25
      • 2021-12-09
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 2015-10-07
      • 2016-11-15
      相关资源
      最近更新 更多