0

我尝试使用 json 模式,这里有一个简单的例子。我正在使用该网站: http: //www.jsonschemavalidator.net/

架构:

{ 
      'Foods':
      { 
        'type': 'array', 
        'items':
        {
          'GoodFoods': { 'type':'string' },
          'NastyFoods': { 'type':'string' },
          'BlendFoods': { 'type': 'string' }
        },      
        'required': ['BlendFoods'],
      }
}

输入 JSON:

{
  "Foods": 
  [
      {
        "GoodFoods": "Pasta",
        "NastyFoods": true,

      }
  ]
}

这里的想法是它应该抱怨“BlendFoods”属性丢失并且 NastyFoods 是布尔值而不是字符串。但相反,它说“未发现错误。JSON 验证架构”。那不是我想要的。

我对此进行了很多尝试,但无法弄清楚我在架构中做错了什么,有什么想法吗?

最好的问候罗布

4

2 回答 2

4

更正后的架构:

{
  "type": "object",
  "properties": {
    "Foods": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "GoodFoods": {
            "type": "string"
          },
          "NastyFoods": {
            "type": "string"
          },
          "BlendFoods": {
            "type": "string"
          }
        },
        "required": [
          "BlendFoods"
        ]
      }
    }
  }
}

请参阅此站点以获取参考和帮助。

于 2016-09-16T09:07:08.240 回答
0

true 后面多了一个逗号。

尝试这个:

  {
      "Foods": 
      [
          {
            "GoodFoods": "Pasta",
            "NastyFoods": true

          }
      ]
    }
于 2016-09-16T09:13:37.950 回答