Question

I have some JSON which is perfect when tested with jsonlint, but gives an Invalid character error when i try to parse it to an object. I've looked at the JSON string and it seems ok. How do I see funny characters that may be hidden??

here is the js fiddle link. http://jsfiddle.net/UexKp/

No correct solution

OTHER TIPS

This may not be the problem you're encountering exactly, but I fixed a similar error in the JSON being returned by my ajax calls (in Internet Explorer only, of course) by specifying that the response type should be interpreted as json, not text. Since I'm using jQuery, this entailed setting the dataType param in the ajax options to "text json", which converts the response appropriately from text (as IE sees it) to JSON.

If this won't work for you, you could also try altering the response type coming from the server directly, assuming you have access to it, so that it correctly reports that the response coming back is JSON, not text.

You could use a debugging proxy like Fiddler (http://www.fiddler2.com/fiddler2/) and then inspect the raw data of the JSON-Request to see if there are some unwanted characters in the response.

Nothing wrong with the JSON: http://jsfiddle.net/UexKp/2/

The { and } are not treated as object literal when they can be treated as block, so having a variable assignment for example fixes it. You could also wrap it with ( and ) as shown in fiddle /1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top