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') ##{"中": "國"}
相關文章
相關標籤/搜索