在 gattle scala 脚本中使用 Jsonpath 提取值

问题描述 投票:0回答:2

下面是我的 json 响应,我尝试在加特林脚本中使用 Scala 解析它,但未返回 x 的值。你能看出可能出了什么错误吗--

[
  [
    {
      "x": "2018-01-23",
      "y": "test"
    },
    {
      "x": "2018-02-02",
      "y": "test1"
    }
]
]

.check(jsonPath(path="$.[0].['x']").is(expected="2018-10-23")))

The error I get is - preparation crashed:       1 (100.0%)
Jackson failed to parse into a valid AST: c.f.j.c.JsonParseExc...
scala gatling jsonpath
2个回答
0
投票

此错误意味着响应的 JSON 格式不正确。 它可能是格式错误的 JSON,也可能根本不是 JSON(通常是 HTML)。检查 logback.xml 并降低日志记录级别以检查响应正文实际是什么。


0
投票

我通过设置请求标头解决了这个问题:

Accept
Content-Type
application/json
。像这样:

Map.entry("Accept", "application/json"), 
Map.entry("Content-Type", "application/json"),
© www.soinside.com 2019 - 2024. All rights reserved.