python中使用了str()方法后,如果不是字符串的话,就没法正常保持中文

python 2 的转码问题真是不好搞,一直用的python3   今天遇到这个问题甚是头疼啊:

解决方法:

用 json包

import json
ll = {'to_station': '\xd6\xa3\xd6\xdd'}
print json.dumps(ll, encoding="gb2312", ensure_ascii=False)

就简单的一句代码,搞得我头疼,惭愧啊!!!!!

猜你喜欢

转载自blog.csdn.net/guan__ye/article/details/82587259