【问题标题】:How to use [*] JSONPath Wildcard In order to retrieve array values如何使用 [*] JSONPath 通配符来检索数组值
【发布时间】:2019-12-04 17:32:47
【问题描述】:

我正在尝试从响应中检索 animalId 值。该数组是动态的,因此我尝试使用def animalIds = response.animals[*].animalId 从数组中检索animalId 值。

回复:

{
    "animals": [
        {
            "animalId": "1234565",
            "animalName": "Tom"
        },
        {
            "animalId": "1234567",
            "animalName": "Dave"
        }
    ]
}

但是,当我执行我的功能文件时,我收到以下错误:

response.animals[*].animalsId
                  ^ in <eval> at line number 1 at column number 18

com.intuit.karate.exception.KarateException: there are test failures !
        at ...(.)
The terminal process terminated with exit code: 1

关于如何解决此问题的任何想法?

【问题讨论】:

    标签: karate jsonpath


    【解决方案1】:

    应该是:

    * def animalIds = $response.animals[*].animalId
    

    阅读文档:https://github.com/intuit/karate#jsonpath-short-cuts

    【讨论】:

      猜你喜欢
      • 2010-12-13
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多