I have read the post for this an yet I still don't know what is happening.
My var "text" is valid according to most JSON online data checker but when I execute the parse it doesn't do anything.
Here is an example code:
<!DOCTYPE html> <html> <body> <h2>Create Object from JSON String</h2> <p id="demo"></p> <script> var text = '{ "zipcodes": [ { "zip": "22312", "city": "Alexandria", "state": "VA" }, { "zip": "22030", "city": "Fairfax", "state": "VA" }, { "zip": "22301", "city": "Tyson's Corner", "state": "VA" }, { "zip": "20148", "city": "Ashburn", "state": "VA" } ]}'; obj = JSON.parse(text); document.getElementById("demo").innerHTML = obj.zipcodes[1].zip + " " + obj.zipcodes[1].city; </script> </body> </html>
Uncaught SyntaxError: Unexpected token ILLEGAL...? And why are you trying to manually create a stringy object? Just create the object!