json

2023-10-31

接口风格类似 pickle

编码

1
import json
2
3
data = data = {"answer": 42, "is_answer": True}
4
json.dumps(data) # 返回 '{"answer": 42, "is_answer": true}'

解码

1
data = '{"answer": 42, "is_answer": true}'
2
json.loads(data) # 返回 {'answer': 42, "is_answer": True}

参考