被坑惨了,一个post搞了一天,时而正常时而错误!
let str = "{‘name‘:‘wanglei‘}";
let obj = JSON.parse(str);
以上会报错:
VM143:1 Uncaught SyntaxError: Unexpected token ‘ in JSON at position 1
at JSON.parse (<anonymous>)
at <anonymous>:1:6
str = ‘{"name":"wanglei"}‘;
这样就好了!
key、value一定要用双引号,遵守json规范
时间: 2024-11-10 02:38:55