Manatee.json 验证失败,但缺少错误消息
我正试图使用以下代码根据特定模式验证JSON文件:Manatee.json 验证失败,但缺少错误消息,manatee.json,Manatee.json,我正试图使用以下代码根据特定模式验证JSON文件: string data = File.ReadAllText("../../../testFiles/create.json"); string schemaText = File.ReadAllText("../../../schemas/request-payload.schema.json"); var serializer = new JsonSerializer(); var json = Js
string data = File.ReadAllText("../../../testFiles/create.json");
string schemaText = File.ReadAllText("../../../schemas/request-payload.schema.json");
var serializer = new JsonSerializer();
var json = JsonValue.Parse(data);
var schema = serializer.Deserialize<JsonSchema>(JsonValue.Parse(schemaText));
var result = schema.Validate(json);
Assert.IsTrue(result.IsValid);
下面是一个测试JSON对象:
{
"template": "TemplateA"
}
上面的JSON验证良好。将该值切换到TemplateB,JSON验证将失败,因为缺少isPrivate,并且它是TemplateB所必需的,但结果不包含有关其失败原因的任何信息
上面列出了我用于运行验证测试的代码。问题可能是您没有设置输出格式。这意味着您只能获得值是否传递的真/假 要获得更多详细信息,您需要使用不同的格式设置。您可以通过 例如: JsonSchemaOptions.OutputFormat = SchemaValidationOutputFormat.Detailed;
可用选项有。太好了,谢谢。向validate调用添加一个options对象就成功了。 JsonSchemaOptions.OutputFormat = SchemaValidationOutputFormat.Detailed;