Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  145] [ 5]  / answers: 1 / hits: 5247  / 11 Years ago, tue, december 3, 2013, 12:00:00

Folks,
Im getting back the following JSON object, which I would like to parse:



{Count:1,Items:[{foo:{S:bar}}]}


If I do the following, I get the 'bar' of the foo item?:



foo = JSON.stringify(result.Items)
foo = JSON.parse(foo)
console.log(foo)

fails if i try:
console.log(foo.bar)


Thanks!


More From » json

 Answers
3

That's because there's no bar property of result.Items — it's an array.



Try



console.log(foo[0].foo.bar);


Or else, when you stringify it in the first place:



var foo = JSON.stringify(result.Items[0].foo);


and then



console.log(foo.bar);


should work.


[#49907] Monday, December 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeffery

Total Points: 180
Total Questions: 114
Total Answers: 117

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;