2

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.

flag

64% accept rate
Are you sure jQuery isn't un-escaping your strings, or are you guessing? – strager Dec 25 '08 at 22:05
I've tested it and inspected the code. It uses eval(string). – Michael Barker Dec 25 '08 at 22:49
Sorry, you're right, eval(string) does work. – Michael Barker Dec 25 '08 at 23:09
2 more reputation points and you'll be able to close your question :) – Georg Dec 26 '08 at 0:19

1 Answer

1

Looks like JSON.parse will do it.

link|flag

Your Answer

get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.