【问题标题】:Json schema not workingJson 架构不起作用
【发布时间】:2016-09-16 08:58:52
【问题描述】:

我尝试使用 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 验证架构”。这不是我想要的。

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

最好的问候 抢

【问题讨论】:

    标签: json json.net jsonschema json-schema-validator


    【解决方案1】:

    更正的架构:

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

    请参阅this site 以获取参考和帮助。

    【讨论】:

      【解决方案2】:

      true 后面多了一个逗号。

      试试这个:

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

      【讨论】:

        猜你喜欢
        • 2015-11-18
        • 1970-01-01
        • 1970-01-01
        • 2017-05-25
        • 2017-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多