I am currently developing a JavaScript add-on which receives JSON from an API. So far, so good I retrieve the JSON and then use eval() to convert this JSON to a JavaScript object. This is where the problems start.
My JSON contains a ‘#text’-property. I evaluated the JavaScript object and found it also has this ‘#text’-property, but I can not call the property since variables with hash-tags are not accepted.
I know two possible solutions (use eval() to convert to an Array or remove the hast-tag), but I would prefer calling the property. Any ideas? Thanks.
Don’t use eval, especially for this. You a json parser, modern browsers already have them.
Here’s a CDN link for json2 http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js