且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用JSON.NET Schema或NJSONSchema根据Draft v4验证JSON Schema?

更新时间:2023-01-17 21:19:39

您可以使用描述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);