python dict 中的中文处理

dict1 = {'中':'国 '}
print dict1 ##{'\xc3\xa4\xc2\xb8\xc2\xad': '\xc3\xa5\xc2\x9b\xc2\xbd'}
import json
json1 = json.dumps(dict1) 
print json1   ##{"\u00e4\u00b8\u00ad": "\u00e5\u009b\u00bd"}
print json1.decode('raw_unicode_escape') ##{"中": "国"}

s = '{"中": "国"}'
dict2 = json.loads(s)
json2 = json.dumps(dict2)
print json2.decode('raw_unicode_escape') ##{"中": "国"}
posted @ 2018-08-28 20:21  机器狗mo  阅读(404)  评论(0编辑  收藏  举报