JSONEncoder and Unicode (Django)
I am using JSONEncoder with Django and to encode dictionaries containing Unicode strings (JSONEncoder.encode()). Resulting JSON is injected in the web pag开发者_StackOverflow社区e. The problem I am facing is that the resulting JSON contains u markers next to the strings and thus is not correctly interpreted in java script
e.g. { u"key" : u"value" }
How can i get rid of it?
Thanks
What you're working with there is the Python equivalent of your JSON object. To get it back into JSON you want to use dumps()
:
import json
mydict = { u"key" : u"value" }
print json.dumps(mydict)
Edit: I'm sorry this isn't exactly relevant to JSONEncoder
, I will try to revise my answer.
精彩评论