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
爲什麼會變成這樣的罰款,如果在內存中完成,但如果從文件加載將失敗?
模式的定義部分是否存在模式「聯繫人」? –