我定义了一个类
class Person(colander.MappingSchema):
name = colander.SchemaNode(colander.String())
age = colander.SchemaNode(colander.Int()
我有一个即将到来的 json 字符串,可能类似于:
{
'name': 'keith',
'age': '20',
'friends': [('1', 'jim'), ('2', 'bob'), ('3', 'joe'), ('4', 'fred')],
'phones': [{'location': 'home', 'number': '555-1212'},
{'location': 'work', 'number': '555-8989'}],
...
}
我只想验证name
and age
,我不关心其他字段(而且我不知道所有其他可能的字段)。有没有办法只验证这两个字段而忽略其他字段?