python中的Unicode [英] Unicode in python
本文介绍了python中的Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我将 elixir 与我的 mysql 数据库和 redispy 与 redis 一起使用,并且我在所有地方都选择了 UTF-8.我想用中文写一些数据,比如{'Info':'8折','Name':'家乐福'}
但我得到的是这样的:
Now I use elixir with my mysql database and the redispy with redis and i select UTF-8 at all the place.
I wanna to get some data writing in chinese like {'Info':‘8折’,'Name':'家乐福'}
but what i got is like this:
{'Info': u'8\u6298', 'Name': u'\u5bb6\u4e50\u798f'}
在我将此字典存储到 redis 并通过 redispy 将其取出后,它变为:
and after i store this dict to redis and get it out by redispy it becomes:
{"Info": "8\u6298", "Name": "\u5bb6\u4e50\u798f"}
我知道如果我在 8\u6298
之前添加 u'
并打印它会告诉我 "8折"
但是有没有函数或此问题的其他解决方案?
I know if i add u'
before 8\u6298
and print it it will shou me "8折"
but is there a function or another solution to this problem?
推荐答案
后者看起来像json,先解码试试:
The latter looks like json, try decoding it first:
import json
resp = '{"Info": "8\u6298", "Name": "\u5bb6\u4e50\u798f"}'
print json.loads(resp)
## {u'Info': u'8\u6298', u'Name': u'\u5bb6\u4e50\u798f'}
这篇关于python中的Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文