我已经定义了一个模式并用它来验证 JSON 对象,但我从来没有得到预期的 ValidationError。例如:
>>> from jsonschema import validate
>>> schema = {
... "type" : "object",
... "properties" : {
... "address" : {"type" : "string"},
... },
... }
>>>
>>> schema
{'type': 'object', 'properties': {'address': {'type': 'string'}}}
>>> validate(instance={"address" : "123 Main St.", "price" : 34.99}, schema=schema)
>>> validate(instance={"address1" : "123 Main St.", "price" : 34.99}, schema=schema)
>>>
>>> validate(instance={"addresdvzdvfafczscss1" : "123 Main St.", "price" : 34.99}, schema=schema)
>>> validate(instance={"addresdvzdvfafczscss1" : "123 Main St.", "price" : 34.99}, schema=schema)
# doctest: +IGNORE_EXCEPTION_DETAIL
>>>
>>> validate(instance={"addresdvzdvfafczscss1" : "123 Main St.",}, schema=schema) # doctest: +IGNO
RE_EXCEPTION_DETAIL
>>>
>>> type(schema)
<class 'dict'>
>>> str(schema)
"{'type': 'object', 'properties': {'address': {'type': 'string'}}}"
>>> validate(instance={"addresdvzdvfafczscss1" : 123,}, schema=schema) # doctest: +IGNORE_EXCEPTIO
N_DETAIL
>>>
谁能看到我做错了什么?