python json unicode - how do I eval using javascript

≯℡__Kan透↙ 提交于 2019-12-10 09:37:41

问题


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


回答1:


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

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


来源:https://stackoverflow.com/questions/2019966/python-json-unicode-how-do-i-eval-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!