python json unicode - 如何使用 javascript 进行评估

发布于 2024-08-16 23:01:58 字数 580 浏览 2 评论 0原文

确实花了很多时间寻找这个。请需要一些帮助。

我正在尝试向我的网络应用程序框架添加多语言功能。为此,我无法将非 ascii 字符作为 JSON 发送。这是我正在做的

  1. 这是我从数据库中获取的内容

    '\xe0\xa4\xa4\xe0\xa5\x87\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4'

    当我打印时,我可以得到哪个

    तेस्त

  2. 我制作响应对象

    response = {'a':'\xe0\xa4\xa4\xe0\xa5\x87\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4'}

  3. 发送响应

    导入json

    sys.stdout.write(json.dumps(response))

  4. 这就是它打印的内容

    Returns u'{"a": "\u0924\u0947\u0938\u094d\u0924"}'

任何帮助,欢迎指点,

谢谢!

鲁沙布

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

  1. 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

    तेस्त

  2. I make the response object

    response = {'a':'\xe0\xa4\xa4\xe0\xa5\x87\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4'}

  3. Send the repsonse

    import json

    sys.stdout.write(json.dumps(response))

  4. This is what it prints

    Returns u'{"a": "\u0924\u0947\u0938\u094d\u0924"}'

Any help, pointers will be welcome

Thanks!

Rushabh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷梦 2024-08-23 23:01:58

这是您想要的输出吗(请参阅 < 的 ensure_ascii 参数代码>json.dumps)?

sys.stdout.write(json.dumps(response, ensure_ascii=False))
{"a": "तेस्त"}

Is this your desired output (see ensure_ascii argument for json.dumps)?

sys.stdout.write(json.dumps(response, ensure_ascii=False))
{"a": "तेस्त"}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文