Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JSON模式中实现条件检查_Json - Fatal编程技术网

在JSON模式中实现条件检查

在JSON模式中实现条件检查,json,Json,我有一个JSON模式结构,其字段如下所示 "fruitColor": { "id": "/fruitType", "type": "string", "title": "Fruit color schema.", "enum": [ "YELLOW", "RED"] } 模式中还有另一个字段,如 "fruits": { "id": "/fruits", "type": "string", "title": "Fruits schema", "en

我有一个JSON模式结构,其字段如下所示

"fruitColor": {
  "id": "/fruitType",
  "type": "string",
  "title": "Fruit color schema.",
  "enum": [
    "YELLOW",
    "RED"]
}
模式中还有另一个字段,如

"fruits": {
  "id": "/fruits",
  "type": "string",
  "title": "Fruits schema",
  "enum": [
    "APPLE",
    "BANANA",
    "POMEGRANATE"]
}

我如何设计这个模式,当用户输入水果颜色为
红色
时,应该允许他/她选择
苹果
石榴
,如果是
黄色
,应该允许选择
香蕉
。有什么方法可以实现这一点吗?

将键
enum
的第二个元素或
red
作为字典,其值是包含
apple
石榴的列表。对钥匙执行相同的操作
“黄色”

像这样:
用户应该在哪里提供输入?我正在执行JSON模式验证。当用户未能遵守我提供的模式时,我将抛出一个错误。如何在enum中实现此字典结构?未将其识别为有效的JSON。
    "fruitColor": {
      "id": "/fruitType",
      "type": "string",
      "title": "Fruit color schema.",
      "enum": [
        "YELLOW": "BANANA",
        "RED": ["apple", "pomegranate"]
         ]
    }