开发者

JSONEncoder and Unicode (Django)

开发者 https://www.devze.com 2022-12-27 15:20 出处:网络
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 fa

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号