如何使用 [*] JSONPath 通配符来检索数组值

How to use [*] JSONPath Wildcard In order to retrieve array values

我正在尝试从响应中检索 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

关于如何解决这个问题有什么想法吗?

应该是:

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

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