我试图将字符串转换为使用JSON.parse
的javascript对象,但它不工作。
我尝试了所有方法,但没有在console.log
上得到任何东西,也没有错误消息。
JSON.parse(`{'exp': '1', 'input': '1d6404f66ed3d72e', 'iterate': 'no'}`);
在实际代码中,我从对象
传递值console.log(JSON.parse(future.onIOPub.data['text/plain']))
当您运行此命令时,您应该看到
Uncaught SyntaxError: Unexpected token ' in JSON at position 1
这个错误是因为你使用了单引号。JSON只接受双引号,如规范
中所述https://www.json.org/json-en.html