3

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.

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

1 Answer 1

2

Looks like JSON.parse will do it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.