user2242044
user2242044

Reputation: 9213

Parsing a JSON with Javascript yields undefined

I am hitting a test API I built with jQuery which gives me a JSON.

In my Javascript, I am doing the following:

var myjson = (getData['responseJSON']['results']);
console.log(myjson);

This yields the below results:

{"A":{"0":1,"1":2},"B":{"0":2,"1":3},"C":{"0":3,"1":4}}

I would like to instead just return the values for A, which I assumed would just be like below. But when I do this I get undefined. What am I doing wrong here?

var myjson = (getData['responseJSON']['results']['A']);
console.log(myjson);

Upvotes: 1

Views: 40

Answers (1)

karthik reddy
karthik reddy

Reputation: 479

var myjson = JSON.parse(getData['responseJSON']['results']); console.log(myjson['A']);

Upvotes: 2

Related Questions