Victor Ferreira
Victor Ferreira

Reputation: 6449

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?

Upvotes: 0

Views: 80

Answers (2)

Victor Ferreira
Victor Ferreira

Reputation: 6449

Saved the file as UTF-8 without BOM (used Notepad++ for that) and that fixed the error

Upvotes: 0

Quentin
Quentin

Reputation: 943564

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

Copy/pasting your code to jsbin makes it visible:

Code screenshot

Delete those three characters and retype them.

Upvotes: 5

Related Questions