一个支持json序列化和反序列化的抽象类。
项目描述
这个库提供了一个抽象基类 JSONable,它使定义易于JSON化的Python对象变得简单。
安装: pip install jsonable
- 示例:
>>> import jsonable >>> >>> >>> class Fruit(jsonable.Type): ... __slots__ = ('type', 'weight') ... ... def initialize(self, type, weight): ... self.type = str(type) ... self.weight = float(weight) ... >>> class Pie(jsonable.Type): ... __slots__ = ('fruit',) ... ... def initialize(self, fruit): ... self.fruit = [Fruit(f) for f in fruit] ... ... >>> pie = Pie([Fruit('apple', 10.3), Fruit('cherry', 2)]) >>> >>> doc = pie.to_json() >>> doc {'fruit': [{'weight': 10.3, 'type': 'apple'}, {'weight': 2.0, 'type': 'cherry'}]} >>> >>> pie == Pie(doc) True
项目详情
下载文件
下载适合您平台文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。
源代码发行版
jsonable-0.3.1.tar.gz (5.5 kB 查看哈希)
构建发行版
jsonable-0.3.1-py2.py3-none-any.whl (11.1 kB 查看哈希)