python2 解决 unicode转中文问题
import json # 避免\x0e 问题 import sys reload(sys) sys.setdefaultencoding('utf-8') # def bbb(): # bbb = {u"111":u"\u73bb\u7483"} print bbb print(json.dumps(bbb).decode("unicode-escape")) def ccc(): # dict1 = {"data": ["\u73bb\u7483", "\u5851\u6599", "\u91d1\u5c5e"]} import json j = json.dumps(dict1) dict2 = j.decode("unicode-escape").decode("unicode-escape") print dict2 def ddd(): ddd = u'\xa0' print(ddd) print(ddd.decode("unicode-escape")) def eee(): eee = "\u73bb\u7483" print(eee) print(eee.decode("unicode-escape")) if __name__ == "__main__": bbb() # ccc() # ddd() # eee()
原文链接:https://blog.csdn.net/yournevermore/article/details/108312388