Skip to content

将对象转为 JSON

foyou edited this page Nov 11, 2021 · 3 revisions

aligo 中所有的数据都是使用 Python 数据类存储,如果直接使用 json.dumps(obj) 转为 json 字符串,将报错:

TypeError: Object of type BaseDrive is not JSON serializable

可使用如下代码替代:

from dataclasses import asdict

json_string = json.dumps(asdict(obj))
Clone this wiki locally