#!coding=utf8
import json
tmp = {1:123, 2:345, 4: '汉字'}
tmp_json_1 = json.dumps(tmp)
tmp_json_2 = json.dumps(tmp, ensure_ascii=False)
print tmp
print tmp_json_1
print tmp_json_2
输出结果是:
{1: 123, 2: 345, 4: '\xe6\xb1\x89\xe5\xad\x97'}
{"1": 123, "2": 345, "4": "\u6c49\u5b57"}
{"1": 123, "2": 345, "4": "汉字"}
通常字典中包含中文的时候,如果直接输出,会是 \uxxxx的形式 。
使用json的 dumps 注意 参数 ensure_ascii=False