如何使用JSON.NET Schema或NJSONSchema根据Draft v4验证JSON Schema? [英] How to validate JSON Schema according to Draft v4 using JSON.NET Schema or NJSONSchema?
问题描述
我一直在研究 JSON.NET架构和
I have been looking into both JSON.NET Schema and NJsonSchema ... Both dont seem to have any propert / method that identifies if JSON Schema is a valid JSON Schema and in accordance with draft v4 Compatible.
难道只有一个异常会识别模式是否有效,即使有效,我将如何检查其v4草案可修改性?
Is it that only an exception that will identify if a schema is valid, and even if its vaid, how will i check that its draft v4 Comatible?
推荐答案
您可以使用描述JSON模式的JSON模式,并使用它来验证JSON.
You can use a JSON schema that describes JSON schema and use that to validate the JSON.
您可以在此处找到副本- http://www.jsonschemavalidator.net/api/jsonschemastore/schema?schemaUrl=schema-draft-v4
You can find a copy here - http://www.jsonschemavalidator.net/api/jsonschemastore/schema?schemaUrl=schema-draft-v4
string draftV4SchemaJson = @"{}"; // replace with content from http://www.jsonschemavalidator.net/api/jsonschemastore/schema?schemaUrl=schema-draft-v4
JSchema draftV4Schema = JSchema.Parse(draftV4SchemaJson);
JObject yourSchemaJson = JObject.Parse(@"{}"); // your schema
bool valid = yourSchemaJson.IsValid(draftV4Schema);
这篇关于如何使用JSON.NET Schema或NJSONSchema根据Draft v4验证JSON Schema?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!