我使用 JSON 模式和 valditory 作为解析器/验证器收到以下模式验证错误。模式已使用 jsonschema.net 自动生成(使用相同的 JSON 数据)
validictory.validator.FieldValidationError: Value '{"bp": [{"category": "bp",
"created": "2013-03-08T09:14:48.148000", "value": 147.0, "day": "2013-03-11T00:00:00",
"value2": 43.0, "id": "dc049c0e-d19a-4e3e-93ea-66438a239712", "unit": "mmHg"}]}'
for field '_data' is not of type object
代码:
import json
import validictory
data = json.dumps({'bp': [{'category': 'bp',
'created': '2013-03-08T09:14:48.148000',
'day': '2013-03-11T00:00:00',
'id': 'dc049c0e-d19a-4e3e-93ea-66438a239712',
'unit': 'mmHg',
'value': 147.0,
'value2': 43.0}]})
schema = {
"type":"object",
"properties":{
"bp": {
"type":"array",
"required":False,
"items":
{
"type":"object",
"required":False,
"properties":{
"category": {
"type":"string",
"default": "bp",
"required":False
},
"created": {
"type":"string",
"default": "2013-03-08T09:14:48.148000",
"required":False
},
"day": {
"type":"string",
"default": "2013-03-11T00:00:00",
"required":False
},
"id": {
"type":"string",
"default": "dc049c0e-d19a-4e3e-93ea-66438a239712",
"required":False
},
"unit": {
"type":"string",
"default": "mmHg",
"required":False
},
"value2": {
"type":"number",
"default":43,
"required":False
},
"value": {
"type":"number",
"default":147,
"required":False
}
}
}
}
}
}
validictory.validate(data,schema)