import json
data ={
'name': liangliang,
'age': 30,
'gender': male,
'address:', beijing
}
json_str = json.dumps(data, ensure_ascii=False, indent=4) #字符缩进4
json_path = './xxx.json'
with open(json_path, 'w') as json_file:
json_file.write(json_str)
该博客主要介绍了如何使用 Python 的 json 模块将数据(如字典)序列化为 JSON 字符串,并将其写入到文件中。示例展示了如何设置确保非 ASCII 字符正确显示以及设置缩进以提高可读性。
11万+

被折叠的 条评论
为什么被折叠?



