Karate Contains在空手道中的每个json ararys中都不起作用

Karate Contains在空手道中的每个json ararys中都不起作用,karate,Karate,尝试使用以下代码验证两个数组中是否都存在已定义的架构,但均无效 * def schema = {"category": "reference","author": "Nigel Rees","title": "Sayings of the Century", "price": 8.95} * def bookdetails= $api.store.book[

尝试使用以下代码验证两个数组中是否都存在已定义的架构,但均无效

* def schema = {"category": "reference","author": "Nigel Rees","title": "Sayings of the Century", "price": 8.95}
* def bookdetails= $api.store.book[*]
* match bookdetails contains schema  

                     
                            
  Json:                     
        {
                "store": {
                    "book": [
                        {
                            "category": "reference",
                            "author": "Nigel Rees",
                            "title": "Sayings of the Century",
                            "price": 8.95
                        }],
                        [{
                            "category": "fiction",
                            "author": "Evelyn Waugh",
                            "title": "Sword of Honour",
                            "price": 12.99
                        },
    {
                            "category": "reference",
                            "author": "Nigel Rees",
                            "title": "Sayings of the Century",
                            "price": 8.95
                        }]}}

由于您是堆栈溢出新手,请阅读以下内容以获得最佳帮助:

问题中的json格式不正确,不是有效的json。以下示例代码起作用:

Feature: Match

Scenario: Match

* def api = 
"""
      {
              "store": {
                  "book": [
                      {
                          "category": "reference",
                          "author": "Nigel Rees",
                          "title": "Sayings of the Century",
                          "price": 8.95
                      },
                      {
                          "category": "fiction",
                          "author": "Evelyn Waugh",
                          "title": "Sword of Honour",
                          "price": 12.99
                      },
                      {
                          "category": "reference",
                          "author": "Nigel Rees",
                          "title": "Sayings of the Century",
                          "price": 8.95
                      }
                      ]
                      }
       }
"""

* def schema = {"category": "reference","author": "Nigel Rees","title": "Sayings of the Century", "price": 8.95}

* def bookdetails = $api.store.book[*]

* match bookdetails contains schema

请不要在堆栈溢出时编辑其他人的答案。此外,您尚未接受以前的答案: