Skip to content

Instantly share code, notes, and snippets.

@srugano
Last active November 5, 2015 09:28
Show Gist options
  • Save srugano/4b81048408aef73a5f80 to your computer and use it in GitHub Desktop.
Save srugano/4b81048408aef73a5f80 to your computer and use it in GitHub Desktop.
when jQuery.parseJSON() throws an invalid json excepion for a Json retrieved from a django backend
// get the json object in the django template :
var data = "{{object|safe}}";
// Parse the JSON data
try
{
// Use jquery's default parser
data = $.parseJSON(data);
}
catch(e)
{
/*
* Fix a bug where strange unicode chars in the json data makes the jQuery
* parseJSON() throw an error (only on some servers), by using the old eval() - slower though!
*/
data = eval( "(" + data + ")" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment