Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uncaught syntaxerror unexpected token U JSON

Tags:

json

I get this error "uncaught syntaxerror unexpected token U" when I run my page in chrome. And in firefox I get, "JSON.parse: unexpected character". I'm returning the json data from a php file and the returning json string is valid. I checked it with http://jsonlint.com/ . Any help would be appreciated... Thanks.

Here's the returned JSON string

[     ["1","Pan Africa Market","\"1521 1st Ave, Seattle, WA\"","47.608941","-122.340145","restaurant"],     ["2","The Melting Pot","14 Mercer St, Seattle, WA","47.624562","-122.356442","restaurant"],     ["3","Ipanema Grill","1225 1st Ave, Seattle, WA","47.606366","-122.337656","restaurant"],     ["4","Sake House","230 1st Ave, Seattle, WA","47.612825","-122.34567","bar"],     ["5","Crab Pot","1301 Alaskan Way, Seattle, WA","47.605961","-122.34036","restaurant"],     ["6","Mexican Kitchen","2234 2nd Ave, Seattle,WA","47.613975","-122.345467","bar"],     ["7","Wingdome","1416 E Olive Way, Seattle, WA","47.617215","-122.326584","bar"],     ["8","Piroshky Piroshky","1908 Pike pl, Seattle, WA","47.610127","-122.342838","restaurant"] ] 
like image 451
kinath_ru Avatar asked Oct 23 '12 01:10

kinath_ru


People also ask

What does this mean SyntaxError unexpected token in JSON at position 0?

Re: Unexpected token in JSON at position 0 This usually means that an error has been returned and that's not valid JSON. Check the browser developer tools console and network tabs. Turn on Debugging and (after reproducing the error) check the web server error logs.

What is uncaught SyntaxError unexpected token?

The "Uncaught SyntaxError: Unexpected token" occurs for multiple reasons: Having a <script /> tag that points to an HTML file instead of a JS file. Getting an HTML response from a server where JSON is expected. Having a <script /> tag that points to an incorrect path.

How do I fix an unexpected token?

This error can occur for a number of reasons, but is typically caused by a typo or incorrect code. Luckily, the SyntaxError: Unexpected token error is relatively easy to fix. In most cases, the error can be resolved by checking the code for accuracy and correcting any mistakes.

How do you handle JSON parsing error?

The best way to catch invalid JSON parsing errors is to put the calls to JSON. parse() to a try/catch block.


1 Answers

That error is normally seen when the value given to JSON.parse is actually undefined. So, I would check the code that is trying to parse this - most likely you are not parsing the actual string shown here.

like image 58
Sean Kinsey Avatar answered Oct 16 '22 09:10

Sean Kinsey