Newtonsoft JSON 架构 - $ref 未解析,获取 url 的身份验证错误

Newtonsoft JSON Schema - $ref is not resolved, getting authentication error for url

我正在尝试使用 URL 中的 $ref 并使用 NewtonSoft.Json.Schema 验证 json 数据。

  1. MainSchema.json

    {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {
            "Data": { "$ref": "http://localhost:49735/api/schema/sample" },
        },
        "required": [ "Data" ]
    }
    
  2. SubSchema.json

    {
       "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": 
        {
            "Data": 
            {
                "type": "array",
                "items": 
                [
                    {
                        "type": "array",
                        "items": 
                        [
                            {
                                "id": "id1",
                                "type": "string",
                            },
                            {
                                "id": "id2",
                                "type": "number"
                            }
                        ]
                    }
                ]
            }
        }
    }
    

我创建了一个示例 Web api 应用程序,用于将子模式下载为 json。 URL 在主模式中引用 http://localhost:49735/api/Schema/Sample api 是在无认证模式下开发的。 我正在使用 NewtonSoft JSON 架构来验证 json 数据。但是在解析 json 模式时它抛出异常。

"The remote server returned an error: (401) Unauthorized."

这可能是您本地网络上的代理问题。您可以尝试配置 .NET 以使用计算机配置的代理 -