) at :1:6 str = '{&quo"/> ) at :1:6 str = '{&quo">

Home  >  Article  >  Web Front-end  >  Things to note when converting string to json

Things to note when converting string to json

一个新手
一个新手Original
2017-10-09 10:06:211613browse

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 = &#39;{"name":"wanglei"}&#39;;

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn