我已经使用 jsonschme 验证器来验证我的 json 输出是否与 Json 文件相对应。
from jsonschema import validate #https://pypi.python.org/pypi/jsonschema
def assertDataMatchesSchema(self, data, schema_file_name):
with open(os.path.join("mha/resource_jsonschema", schema_file_name)) as schema_file:
validate(data, json.load(schema_file))
这是我的jsonschema:
{ "code": {"type":["string","null"]},
"codingMethod": {"type":["string","null"]},
"priority":{"type":["string","null"]},
"status":{"type":["string","null"]} ,
"description" : {"type" : "string"}
}
终端输出:
SchemaError: {u'type': u'string'} is not of type u'string'
Failed validating u'type' in schema[u'properties'][u'description']:
{u'type': u'string'}
On instance[u'description']:
{u'type': u'string'}
问题:如果我从上面的文件中删除描述字段或更改为其他名称,它可以工作,但我需要描述字段(需要 nne)。有什么办法可以解决这个问题??
如果我在那里使用“类型” 字段,也会出现同样的问题。