skip to Main Content

I have this JSON response (contained in response variable):

{
  "data": [
    {
      "requestedUsername": "string",
      "hasVerifiedBadge": true,
      "id": 0,
      "name": "string",
      "displayName": "string"
    }
  ]
}

And I want to get values like "name", "displayName", etc… But I can’t figure out how to get to them, because it’s located inside a dictionary which, in turn, is located inside an array.

I tried beginning with this:

console.log(response.data[0])

But even it returns undefined . So what would the solution be?

2

Answers


  1. Chosen as BEST ANSWER

    Problem solved. Solution:

    console.log(response.data.data[0].name)
    

  2. If the variable "response" indeed has that value you should be able to get them with:
    var theName = response.data[0].name;

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search