简体   繁体   中英

Unexpected token when parsing JSON

friends

This is my code

var j = '[{"id":"151","name":"As aventuras de PI","picture":null}]'
JSON.parse(j)

and it keeps saying "unexpected token"

This happens in the main page of my website. But in many other pages it works fine and I use the same functions (in PHP and in Javascript) to generate this string

Whats wrong with my JSON?

You have a non-printing character between ' and [ .

Copy/pasting your code to jsbin makes it visible:

代码截图

Delete those three characters and retype them.

将文件另存为UTF-8,不带BOM(为此使用Notepad ++),并修复了错误

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM