Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  161] [ 3]  / answers: 1 / hits: 51804  / 7 Years ago, fri, june 23, 2017, 12:00:00

I have a json-object, which I print to the screen (using alert()-function):



alert(object);


Here is the result:



enter



Then I want to print the value of the id to the screen:



    alert(object[id]); 


The result is this:



enter



As you can see, the value of key id is not(!!!) undefined.



What the hell is going on here?!


More From » json

 Answers
66

Looks like your json object is not really an object, it's a json string. in order to use it as an object you will need to use a deserialization function like JSON.parse(obj). Many frameworks have their own implementation for deserializing a JSON string.

When you try to do alert(obj) with a real object the result would be [object Object] or something like that


[#57324] Wednesday, June 21, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;