【问题标题】:Why response.item[*].id doesn't work in karate JsonPath为什么 response.item[*].id 在空手道 JsonPath 中不起作用
【发布时间】:2020-04-28 19:56:21
【问题描述】:

例如https://github.com/json-path/JsonPath#path-examples$.store.book[*].author可以返回所有书籍的作者; 但它不适用于我的代码:* print transactionIds = response.items[*].id

在我的回复中,返回了 100 个项目,并且单个记录 id 可以通过给出索引号来打印出来,例如"*打印 response.items[0].id"

但我想获取所有记录 id 并放入一个新数组中,就像 JsonPath#path-examples 获取所有书籍的所有作者一样。

为什么 response.items[*].id 在空手道 API 测试中对我不起作用?

【问题讨论】:

    标签: karate jsonpath


    【解决方案1】:

    右侧的 JsonPath 需要一个 $ 前缀。试试这个:

    * def transactionIds = $response.items[*].id
    * print transactionIds
    

    请参考文档:https://github.com/intuit/karate#get

    【讨论】:

      猜你喜欢
      • 2021-05-20
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多