【问题标题】:Printing database query response as json array/list in Karate在空手道中将数据库查询响应打印为 json 数组/列表
【发布时间】:2020-07-13 05:07:10
【问题描述】:

我在空手道中使用 DBUtils 的 readRows() 方法并以地图列表的形式接收响应,我将其保存为名为 response 的 json 变量。数据如下所示:

[
      {
        "ID": "001"
      },
      {
        "ID": "002"
      },
      {
        "ID": "003"
      }
]

断言适用于

* match response[*].ID == ["001", "002", "003"]

但它不打印任何东西

* print response[*].ID

我期待它会打印三个 id 的 ["001", "002", "003"]。知道为什么它不打印任何东西吗?

【问题讨论】:

  • @PeterThomas 你在我的另一个问题中给出的答案没有帮助,就像这个问题的答案一样
  • 这个问题与 DBUtils BTW 无关,这让我很困惑。提示:print 仅支持 JS。当您看到 *.. 时,它就是 JsonPath。阅读文档:github.com/intuit/karate#get
  • @mitymouse 将 response[*].ID 存储在一个变量中并打印该变量。
  • @PeterThomas 谢谢,这有帮助。你能不能像上面那样把我的问题联系起来,因为它与此无关? @Neodawn 感谢您的提示。实际上,我试过了,但没有奏效。您必须使用 Peter 在上面的链接 (github.com/intuit/karate#get) 中提到的内容来存储它。所以对于上面的例子,首先是* def output = $response[*].ID,然后是* print output。如果您尝试像* print $response[*].ID 那样直接打印它,它将无法正常工作。
  • @mitymouse 完成。现在你知道该怎么做了;)

标签: json karate


【解决方案1】:

这样做:

* def output = $response[*].ID
* print output

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多