#-*-coding:utf-8-*-
import json
informations = {
'姓': '张',
'名': '三',
'性别': '男',
'年龄': 18,
'成绩': {
'语文': 86,
'数学': 66
}
}
path = '成绩单.json'
json_str = json.dumps(informations, ensure_ascii=False, indent=4) # 缩进4字符
with open(path, 'w') as json_file:
json_file.write(json_str)
使用 notepad++ 打开成绩单.json
文件,可以看到如下图: