作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我想用 JSON 模式数组来描述,它应该包含零个或多个预定义值。为简单起见,让我们有这些可能的值:one
、two
和 three
。
正确的数组(应该通过验证):
[]
["one", "one"]
["one", "three"]
不正确:
["four"]
现在,我知道应该使用 "enum"
属性,但我找不到相关信息将它放在哪里。
选项A(在“items”
下):
{
"type": "array",
"items": {
"type": "string",
"enum": ["one", "two", "three"]
}
}
选项 B:
{
"type": "array",
"items": {
"type": "string"
},
"enum": ["one", "two", "three"]
}
最佳答案
选项 A 正确,满足您的要求。
{
"type": "array",
"items": {
"type": "string",
"enum": ["one", "two", "three"]
}
}
关于arrays - 在 JSON 模式中定义枚举数组的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30924271/
我是一名优秀的程序员,十分优秀!