<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script>
var str = "{ 'foo': 'bar' }";
var json = JSON.parse(str);
</script>
</body>
</html>
This code throws an error on the second variable statement. Why? (Chrome says "unexpected token ILLEGAL", Firefox says "JSON.parse")
You're supposed to use double, not single quotes:
var str = '{ "foo": "bar" }';
var json = JSON.parse(str);
json['foo']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With