在空手道 BDD 中用双引号提取 json 数据

Extract json data with double quotes in Karate BDD

如何从下面的 json 响应负载中提取身份验证令牌以用于后续请求(似乎我遇到了问题,因为键值中的键有双引号)?

Feature: test oauth Background: * url https://xxx.yyy.com
Scenario: Get xxx-subject Given path xxx/oauth/internal/proof/srvc And headers someData When method get Then status 200 And print 'authorization :'$[2]

响应负载:

{
    "xxx-gateway-proof":"xxxx",
    "xxx-subject":" yyy",
    "authorization":"Bearer zzz"
}

不是双引号,而是连字符 - 导致 JSON 键出现问题,因为它被解释为减号。

我刚刚测试了下面的,它有效:

* def response =
"""
{
  "xxx-gateway-proof": "xxxx",
  "xxx-subject":" yyy",
  "authorization": "Bearer zzz"
}
"""
* def proof = response['xxx-gateway-proof']
* match proof == 'xxxx'