【发布时间】:2019-11-22 10:06:13
【问题描述】:
我使用 python 和 json 模式作为数据验证工具,下面是我的模式:
ValidatorSchema = {
"type": "object",
"required": ["data"],
"properties": {
"data":
{
"type": "object",
"required": ["account", "password", "clientType"],
"properties": {
"account": {
"type": "string"
},
"password": {
"type": "string"
},
"clientType": {
"type": "integer",
"enum": [ClientTypeEnum.USER_EMAIL.code, ClientTypeEnum.USER_MOBILE.code,
ClientTypeEnum.USER_MINA.code,
ClientTypeEnum.USER_WECHAT.code]
}
}
}
}
}
还有我的数据:
{
"data": {
"account": "ccl",
"password": "12345678",
"level": 0,
"client_type": 100
}
}
但验证器总是向我显示错误,我该如何解决它:
SchemaError: b'{\n "data": {\n "account": "ccl",\n "password": "12345678",\n "level": 0,\n "client_type": 100\n }\n}' is not of type 'object'
【问题讨论】:
-
您是否尝试将数据作为字符串传递给验证函数?我们可以看看您导入 JSON 并将其传递给函数的代码吗?
-
使用jsononpickle.decode(request.data)处理数据后,现在可以了。
标签: python-3.x jsonschema