main.py
Costs 1 credit
加载编辑器中...
输出 Output执行成功
# 运行代码后,输出将显示在这里 # 按 Ctrl+Enter 快速运行
Terminal (Simulated)Install commands are simulated only, no real network requests
$
Step 1: Python 转 JSON
json.dumps() 是“序列化”步骤:把内存对象编码成可传输文本。
底层逻辑:
Python 字典是运行时对象,网络传输和文件存储通常需要字符串。
序列化就是把对象结构编码成标准 JSON 文本。
Python 字典是运行时对象,网络传输和文件存储通常需要字符串。
序列化就是把对象结构编码成标准 JSON 文本。
你的任务:
- 导入
json模块 - 创建字典
person = {"name": "Alice", "age": 25, "city": "Beijing"} - 使用
json.dumps()转为 JSON 字符串并输出
Self-Check List
- 将 Python 对象转为 JSON
Transfer Template
import json
After completing this step, you should be able to independently explain and reproduce this concept, then apply it to similar problems.