学习内容
json.dumps 将列表转换为文本,ensure_ascii=False 保留中文可读性。将示例存到新的练习目录运行,它会创建或覆盖 todo-demo.json。
把读出的列表打印出来,应该能看到“复习循环”。
操作示例
import json
from pathlib import Path
file = Path("todo-demo.json")
file.write_text(json.dumps(["复习循环"], ensure_ascii=False), encoding="utf-8")
print(json.loads(file.read_text(encoding="utf-8")))