python中marshmallow库如何使用

python中marshmallow库如何使用

概念

1、是专门用来支持 python 对象和原生数据相互转换的库,如实现 object -> dict,objects -> list, string -> dict, string -> list 等的转换功能。

2、提供了非常丰富的数据类型转换和校验 API,帮助我们快速实现数据的转换。

实例

调用 Schema 的 load 事件:

schema=UserSchema()
users=schema.load(data,many=True)
print(users)

输出结果:

[User(name='Germey',age=23),User(name='Mike',age=20)]

以上就是python中marshmallow库的使用,希望对大家有所帮助。更多python学习指路:python基础教程