我一直在研究需要引用其他几个架构文件的架构,并且基本上在 jsonschemavalidator.net 中工作,然后将位复制回 github 存储库。今天我到达了我保存的工作版本,您可以看到架构,并且数据对 undefinedResource 失败,这是意料之中的,因为它没有在我的架构中定义。
https://www.jsonschemavalidator.net/s/JrLE3dI0
我创建了一个简单的表单应用程序,用于测试我从该页面上的“查看源代码”按钮中提取的代码。
WebClient wget = new System.Net.WebClient();
Uri schemaUri = new System.Uri(textBox1.Text);
var jsonSchema = wget.DownloadString(schemaUri.AbsoluteUri);
JObject json = JObject.Parse(textBox3.Text);
JSchema schema = JSchema.Parse(jsonSchema);
IList<ValidationError> errors;
bool valid = json.IsValid(schema, out errors);
textBox2.Clear();
if (valid == false)
{
foreach (var err in errors)
{
textBox2.Text += (err.Path + "\r\n") + (err.Message) + "\r\n";
}
}
else
{
textBox2.Text = json.ToString();
}
它没什么特别的,即使是一个按钮,也可以点击一下。除了从在线源中删除 api 内容之外,我觉得这段代码应该返回相同的结果。除了当我传入在线工作的模式时,我收到以下错误:
Newtonsoft.Json.Schema.JSchemaReaderException
HResult=0x80131500
Message=Could not resolve schema reference 'https://raw.githubusercontent.com/jeffpatton1971/randomschema/main/resources/definedResource.json#'. Path 'properties.definedResources.items', line 10, position 16.
Source=Newtonsoft.Json.Schema
StackTrace:
at Newtonsoft.Json.Schema.Infrastructure.JSchemaReader.ResolveDeferedSchema(DeferedSchema deferedSchema)
at Newtonsoft.Json.Schema.Infrastructure.JSchemaReader.ResolveDeferedSchemas()
at Newtonsoft.Json.Schema.Infrastructure.JSchemaReader.ReadRoot(JsonReader reader, Boolean resolveDeferedSchemas)
at Newtonsoft.Json.Schema.JSchema.Load(JsonReader reader, JSchemaReaderSettings settings)
at Newtonsoft.Json.Schema.JSchema.Parse(String json, JSchemaReaderSettings settings)
at Newtonsoft.Json.Schema.JSchema.Parse(String json)
at jsonTesting.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\JeffreyPatton\source\repos\jsonTesting\jsonTesting\Form1.cs:line 31
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at jsonTesting.Program.Main() in C:\Users\JeffreyPatton\source\repos\jsonTesting\jsonTesting\Program.cs:line 19
非常感谢任何帮助,所有引用的 URL 都可以正常工作并在在线验证器中正确返回,所以我觉得我在我举起的少量代码中做了一些愚蠢的事情。