Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  30] [ 2]  / answers: 1 / hits: 19898  / 13 Years ago, mon, august 29, 2011, 12:00:00

I am receiving back from the server a JSON string like this one:



[{Title:Windows,URL:http://www.domain.com/soft/,Type:out,Price:140}]


I save it into a variable stringand I am trying to convert it to a JSON object like this:



var json = JSON.parse(string);


after that I get the Object which looks great:



[Object]
->Price: 140
->Title: Windows
->Type: out
->URL: http:www.domain.com/soft/
->__proto__: Object


but when I try to acces it using for example json.Price I get undefined, any idea what I'm missing here?


More From » json

 Answers
5

As you wrap your content with [] you get an array with one object. So this should work:



json[0].Price


But you can also remove the brackets.


[#90374] Friday, August 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;