views:

2073

answers:

1

I am currently using Django to construct JSON encoded objects which a retrieved using jQuery.getJSON(). The standard simplejson encoder encodes strings according to the JSON "standard", i.e. any string containing a '/' is translated to '\/'. Therefore if one of my parameters is a url, e.g. http://example.com/image.jpg it is passed to the client as http:\/\/example.com\/image.jpg. JQuery does not decode these strings (it does a straight eval), therefore it I try to use the url as the src attribute for an image it does not work. What is the best way to handle strings (e.g. urls) in JavaScript that have been "JSON-escaped"?

Update: There was a bug elsewhere in the code, jQuery.getJSON() does the correct unescaping.

+1  A: 

Looks like JSON.parse will do it.

nicerobot