Dobes Vandermeer
Dobes Vandermeer

Reputation: 8810

Can I fix the error: "JSON.parse: unexpected character"

I'm running into this error. The app seems to work OK but it causes Firebug to stop the scripts.

   JSON.parse: unexpected character
   Line 9 (all.js)

The line in question looks like this:

FB.provide('JSON',{stringify:function(a){if(window.Prototype&&Object.toJSON){return Object.toJSON(a);}else return JSON.stringify(a);},parse:function(a){return JSON.parse(a);},flatten:function(c){var a={};for(var b in c)if(c.hasOwnProperty(b)){var d=c[b];if(null===d||undefined===d){continue;}else if(typeof d=='string'){a[b]=d;}else a[b]=FB.JSON.stringify(d);}return a;}});

I believe the exception is thrown by Firefox's built-in JSON parser, in the parse method defined on that line. The string being passed to parse looks like this:

"cb=f49f4551da8c7e&origin=http%3A%2F%2Flocalhost%3A9292%2Ff3726c758943f5&relation=parent&transport=postmessage&frame=f2b4bb038098548&code=2.AQ...fU&signed_request=_7hf...E3OCJ9&access_token=AAADj6D4s...ZDZD&expires_in=6650"

Obviously this is not a valid JSON string, thus the parse error.

The string comes from an event delivered using the xd_proxy.php somehow, the above string is the hash on the URL for that iframe.

I've searched around a bit and didn't see any useful information about this error.

Upvotes: 3

Views: 4675

Answers (1)

Dobes Vandermeer
Dobes Vandermeer

Reputation: 8810

It turns out that this exception is correctly caught and handled by the javascript code that calls it, but because I had Firebug set to "break on all errors" it stops execution regardless of whether that exception is caught.

So the fix is actually to turn off "break on all errors" in Firebug, it isn't really a problem with the Facebook scripts at all.

Upvotes: 7

Related Questions