class Person:
first_name = superjson.Property()
last_name = superjson.Property()
posts = superjson.Collection(Post)
class Post:
title = superjson.Property()
description = superjson.Property()
# ^^^ this approach is very similar to Django models/forms
然后,假设JSON是这样的:
^{pr2}$我想让它建立一个适当的Person
对象,其中包含所有内容:
p = superjson.deserialize(json, Person) # note, root type is explicitly provided
print p.first_name # 'John'
print p.last_name # 'Smith'
print p.posts[0].title # 'title #1'
# etc...
所以,我在找这个superjson
。有人见过类似的东西吗?在
Colander,与limone相结合就可以做到这一点。在
使用
colander
定义架构:然后传入JSON数据结构:
^{pr2}$相关问题 更多 >
编程相关推荐