eva*_*nal 35 .net c# json json.net jsonschema
希望这对其他人来说并不明显,因为我发现http://json-schema.org/上的文档缺乏更精细的细节.我正在获得一个json块,其中包含一些可以为null或字符串的属性.如何在json模式中指定(由json.NET的JsonSchema.Parse方法解析)一个值可以是null类型还是类型字符串?
有什么简单的我缺少像为类型提供数组?例如;
"member_region": { "type": [ "string", null ] } // this throws an exception
Run Code Online (Sandbox Code Playgroud)
另外,有没有人比json-schema.org有更好的json架构细节来源?我在哪里可以找到更多的例子?我不想阅读一篇大文档/规范来找到一些可以在10行示例中轻松演示的内容.
Exp*_*lls 69
来自http://json-schema.org/latest/json-schema-validation.html#anchor79
此关键字的值必须是字符串或数组.如果它是一个数组,那么数组的元素必须是字符串,并且必须是唯一的.
字符串值必须是核心规范定义的七种基本类型之一.
然后我们参考类型:http://json-schema.org/latest/json-schema-core.html#anchor8
它列出了字符串和null.尝试:
"member_region": { "type": "string, null" }
Run Code Online (Sandbox Code Playgroud)
zar*_*ior 17
如果您使用数组语法,则扩展爆炸药的答案:
"member_region": { "type": [ "string", "null" ] } // this works
Run Code Online (Sandbox Code Playgroud)
因为您声明的是类型而不是示例,所以您不应该这样做:
"member_region": { "type": [ "string", null ] } // this throws an exception
Run Code Online (Sandbox Code Playgroud)
Epi*_*ene 12
anyOf也可能有用。
"member_region": {
"anyOf": [
{ "type": "string" },
{ "type": "null" },
]
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18258 次 |
| 最近记录: |