在使用json.dumps時要注意一個問題
import json
print json.dumps('中國')
# 輸出結果:"\u4e2d\u56fd"
輸出的會是'中國' 中的ascii 字符碼,而不是真正的中文。
這是因為json.dumps 序列化時對中文默認使用的ascii編碼.想輸出真正的中文需要指定ensure_ascii=False:
import json
print json.dumps('中國')
# 輸出結果:"\u4e2d\u56fd"
print json.dumps('中國',ensure_ascii=False)
# 輸出結果:"中國"
轉自:http://www.cnblogs.com/biangbiang/archive/2013/02/19/2916780.html