Take a look at this code:
<script>
try {
var jsonObject = JSON.parse("{ ID: 1, 'Code':'001', 'Name':'john', 'HasParent':false, 'HasGrandParent':false, 'IsAgent':False }");
document.write(jsonObject.Name);
}
catch(error) {
document.write(error);
}
</script>
Here is the error message:
Unexpected token I in JSON at position 2
I'm confused about what's causing this. Can anyone help?
==================
Big thanks to JayTheKay for the helpful response.
Here are the issues and solutions:
- Strings should be enclosed in double quotes
- Boolean values should be lowercase, so "False" should be "false"
- The first key,
ID
, should not be surrounded by double quotes