🧠 Python 标准库 - json
模块详解(JSON 数据处理)
json
模块用于在 Python 与 JSON(JavaScript Object Notation)格式之间进行转换,是常用的数据交换格式。
🔄 一、Python 对象转 JSON 字符串(序列化)
import json
数据 = {
"name": "小明",
"age": 20,
"is_student": True,
"scores": [90, 88, 92]
}
json字符串 = json.dumps(数据, ensure_ascii=False)
打印(json字符串) # 输出:{"name": "小明", "age": 20, "is_student": true, "scores": [90, 88, 92]}