I have been working on a post for a day, sometimes it is normal and sometimes it is wrong!
let str = "{'name':'wanglei'}"; let obj = JSON.parse(str);
The above will report an error:
VM143:1 Uncaught SyntaxError: Unexpected token ' in JSON at position 1 at JSON.parse (<anonymous>) at <anonymous>:1:6 str = '{"name":"wanglei"}';
That’s it!
key and value must be in double quotes and comply with json specifications
The above is the detailed content of Things to note when converting string to json. For more information, please follow other related articles on the PHP Chinese website!