开发者

python json unicode - how do I eval using javascript

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 t开发者_如何学编程his 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


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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜