【运行代码】
import json
data = {'姓名': 'xiaowan', 'age': 20}
df1 = json.dumps(data)
df2 = json.dumps(data, indent=4)
df3 = json.dumps(data, indent=4, ensure_ascii=False)
print(df1)
print(df2)
print(df3)
【运行结果】
{"\u59d3\u540d": "xiaowan", "age": 20}
{
"\u59d3\u540d": "xiaowan",
"age": 20
}
{
"姓名": "xiaowan",
"age": 20
}