问题描述
真的花了很多时间来寻找这个。请需要帮助。
我正在尝试向我的Web应用程序框架添加多语言功能。为此,我无法将非ascii字符作为JSON发送。这是我在做什么
-
这是我从数据库中得到的内容
'\xe0\xa4\xa4\xe0\xa5\x87\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4 '
在我打印时,这可以给我
ेस>
-
我创建响应对象
response = {'a':'\xe0\xa4\xa4\xe0\ \xa5\x87\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4'}
-
发送回复
导入json
sys.stdout.write(json.dumps(response))
-
这是它的打印内容
返回u'{ a: \u0924 \u0947\u0938\u094d\u0924}'
任何帮助,欢迎使用指针
谢谢!
Rushabh
这是您所需的输出(有关)?
sys .stdout.write(json.dumps(response,sure_ascii = False))
{ a:غेस्غ}
Really spent a lot of time searching for this. Please need some help.
I am trying to add multilingual feature to my web app framework. For this I am unable to send non ascii characters as JSON. Here is what I am doing
Here is what I get from the database
'\xe0\xa4\xa4\xe0\xa5\x87\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4'
which when I print gives me which is okay
तेस्त
I make the response object
response = {'a':'\xe0\xa4\xa4\xe0\xa5\x87\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4'}
Send the repsonse
import json
sys.stdout.write(json.dumps(response))
This is what it prints
Returns u'{"a": "\u0924\u0947\u0938\u094d\u0924"}'
Any help, pointers will be welcome
Thanks!
Rushabh
Is this your desired output (see ensure_ascii
argument for json.dumps
)?
sys.stdout.write(json.dumps(response, ensure_ascii=False))
{"a": "तेस्त"}
这篇关于python json unicode-如何使用javascript进行评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!