python – JSON模式不验证有效数据(验证)
发布时间:2020-12-20 13:34:17 所属栏目:Python 来源:网络整理
导读:以下数据 JSON模式(使用具有相同数据的 JSON模式生成器生成)应该正确验证.但是我在这里收到了一个valdation错误. 验证基于验证模块. import jsonimport validictoryimport jsonschemadata = [{u'text': u'h1The quick brown fox/h1',u'title': u'hello world
以下数据
JSON模式(使用具有相同数据的
JSON模式生成器生成)应该正确验证.但是我在这里收到了一个valdation错误.
验证基于验证模块. import json import validictory import jsonschema data = [{u'text': u'<h1>The quick brown fox</h1>',u'title': u'hello world',u'location': u'Berlin',u'created': u'2013-03-12T12:13:14'}] schema = { "$schema": "http://json-schema.org/draft-03/schema","id": "http://jsonschema.net","required": False,"type": "object","properties": { "0" : { "id": "http://jsonschema.net/0","properties": { "created" : { "id": "http://jsonschema.net/0/created","type": "string" },"location" : { "id": "http://jsonschema.net/0/location","text" : { "id": "http://jsonschema.net/0/text","title" : { "id": "http://jsonschema.net/0/title","type": "string" } } } } } print validictory.validate(data,schema) validictory.validator.FieldValidationError: Value [{u'text': u'<h1>The quick brown fox</h1>',u'created': u'2013-03-12T12:13:14',u'title': u'hello world'}] for field '_data' is not of type object 解决方法
您的验证错误告诉您问题是什么……
它说价值[{u’text’:你’< h1>快速的棕色狐狸< / h1>‘,u’created’:u’2013-03-12T12:13:14′,你的位置’:你’Berlin’,u’title’:u’hello world’}]字段’_data’不是类型对象, 此外,看起来您在jsonschema.net修复了它们如何使用id之前生成了这个模式,这在规范下是不正确的,因此您可能想要删除这些属性. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |