0
我生成的Json架构不在当前存在的类中。自动生成的架构仅在内存中完成时才起作用
JSchemaGenerator generator = new JSchemaGenerator();
JSchema schema = generator.Generate(typeof(Client));
这将验证正常,但是,我需要把对依赖关系(你不能从类做的),所以我复制架构结果到一个文件中。现在,该文件将在http://www.jsonschemavalidator.net/上验证为无效。然而,当我尝试使用加载了下列文件:
using (StreamReader file = File.OpenText("c:\\myJson.json"))
{
file.BaseStream.Position = 0;
using (JsonTextReader reader = new JsonTextReader(file))
{
JSchema schema2 = JSchema.Load(reader);
}
}
我总是会得到错误的任何内部引用的文件中:
"Contact": {"$ref": "#/definitions/Contact"},
An exception of type 'Newtonsoft.Json.Schema.JSchemaReaderException'
occurred in Newtonsoft.Json.Schema.dll but was not handled in user code
Additional information: Could not resolve schema reference
'#/definitions/Contact/ Path 'definitions.Contact' Line 120, position 20
为什么会变成这样的罚款,如果在内存中完成,但如果从文件加载将失败?
模式的定义部分是否存在模式“联系人”? –