Clark Jeria
Clark Jeria

Reputation: 53

JSON Parse : The Famous Unexpected Token

When I do an Ajax async call using JQuery it fails with the following message:

Syntax Error: Unexpected Token

So I capture the output and its

{"formattedBasePrice":"<span class=\\"amount\\">&#36;30,000<\/span>","formattedTotalPrice":"<span class=\\"amount\\">&#36;30,000<\/span>","formattedVariationTotal":"<span class=\\"amount\\">&#36;0<\/span>"}

The funny part is that if I copy/paste that JSON from the Browser Console and try to parse it, it WORKS!

So, I change my files to UTF8 without BOM but the problem still happend.

So the next is to remove the invalid invisible characters (the only reason that make the JSON parse works if I enter the string directly)

And my question is, Anyone knows what are the most common invalid invisible characters? I already try null (\0) but nothing happend.

Thanks!

Upvotes: 0

Views: 160

Answers (1)

Patrick
Patrick

Reputation: 12744

The JSON is not valid. Can you try it like this:

{"formattedBasePrice": "<span class=\"amount\">&#36;30,000</span>", "formattedTotalPrice": "<span class=\"amount\">&#36;30,000</span>", "formattedVariationTotal": "<span class=\"amount\">&#36;0</span>"}

Upvotes: 1

Related Questions