【发布时间】:2016-01-18 10:37:40
【问题描述】:
我正在尝试使用来自 URL 的 $ref 并使用 NewtonSoft.Json.Schema 验证 json 数据。
-
MainSchema.json
{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "Data": { "$ref": "http://localhost:49735/api/schema/sample" }, }, "required": [ "Data" ] } -
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 Schema 来验证 json 数据。但是在解析 json 架构时它会抛出异常。
"The remote server returned an error: (401) Unauthorized."
【问题讨论】:
-
尝试将 $ref uri 复制到浏览器中,并使用 Web 开发人员工具中的网络工具测试响应。或使用
curl。如果有 401 响应,则错误在您的服务器配置中。 -
从浏览器可以正常工作。似乎只是因为无法使用 n/w 代理
标签: json json.net jsonschema