指定的值可以是字符串或空以JSON模式 [英] specify a value can be a string or null with json schema
问题描述
我希望这不是明摆着给别人,因为我找到了文档在 http://json-schema.org/ 是缺乏更精细的细节。我得到的JSON块的一些属性,可以为空或字符串。如何指定,在一个JSON模式(由json.NET的 JsonSchema.Parse
法解析),该值的类型可以是空或字符串类型的?
Hopefully this isn't obvious to others because I find the docs at http://json-schema.org/ to be lacking in finer details. I'm getting a block of json with some properties that can be null or a string. How do you specify, in a json schema (to be parsed by json.NET's JsonSchema.Parse
method), that a value can be of type null or type string?
有一些简单的我失踪了一样的类型提供一个数组?例如;
Is there something simple I'm missing like supplying an array for the type? For example;
"member_region": { "type": [ "string", null ] } // this throws an exception
此外,没有任何人有JSON模式的详细信息更好的来源则json-schema.org?我在哪里可以找到一个更大的选择的例子吗?我不想看一个大的DOC /规格找到的东西,可以很容易地证明在10日线的例子。
Also, does anyone have a better source for json schema details then the json-schema.org? Where can I find a larger selection of examples? I don't want to read a big doc/spec to find something that can easily be demonstrated in a 10 line example.
推荐答案
从<一个href="http://json-schema.org/latest/json-schema-validation.html#anchor79">http://json-schema.org/latest/json-schema-validation.html#anchor79
该关键字的值必须是一个字符串或数组。如果它是一个数组,数组的元素必须是字符串,并且必须是唯一的。
The value of this keyword MUST be either a string or an array. If it is an array, elements of the array MUST be strings and MUST be unique.
字符串值必须是由核心规范中确定的七项基本类型之一。
String values MUST be one of the seven primitive types defined by the core specification.
然后我们参考类型:<一href="http://json-schema.org/latest/json-schema-core.html#anchor8">http://json-schema.org/latest/json-schema-core.html#anchor8
它列出字符串和空。尝试:
It lists string and null. Try:
"member_region": { "type": [ "string", "null" ] }
这篇关于指定的值可以是字符串或空以JSON模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!