简体   繁体   中英

Trouble accessing JSON array

The data looks like this:

[
  {
    "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"
  },

And I'm trying to output something from passports like this:

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

res is the JSON object containing the data show below.

try

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

it looks like res is an array

The res JSON objects contains a list of items. thats why its not giving any value. Please try this .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM