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

Things to note when converting string to json

一个新手
Release: 2017-10-09 10:06:21
Original
1644 people have browsed it

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);
Copy after login

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;;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template