Here is my code:
<script>
try {
var ob = JSON.parse("{ ID: 1, 'Code':'001', 'Name':'john', 'HasParent':false, 'HasGrandParent':false, 'IsAgent':False }");
document.write(ob.Name);
}
catch(err) {
document.write(err);
}
</script>
Here is the error message:
Unexpected token I in JSON at position 2
I have no idea what's happening. What's wrong here?
==================
Thanks for the answer from JayTheKay below.
The problems and fixes are:
- use double quote for string
- boolean value is lower case, so "False" is wrong, "false" is correct
- this first key name
ID
is not wrapped with double quote