在空手道BDD中提取带有双引号的json数据 [英] Extract json data with double quotes in Karate BDD

查看:53
本文介绍了在空手道BDD中提取带有双引号的json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从下面的json响应有效负载中提取身份验证令牌,以在后续请求中使用(好像我遇到麻烦了,因为键值中的键具有双引号)?

How do I extract auth token from the below json response payload to use in the subsequent request (seems like I am having trouble as the key in the key value has double quotes)?

功能:test oauth 背景: *网址https://xxx.yyy.com
场景:Get xxx-subject 给定路径xxx/oauth/internal/proof/srvc 和标题someData 当方法get 然后状态200 并打印'authorization :'$[2]

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密钥中引起了问题,因为它被解释为减号.

It is not to double quotes, it is the hyphen - sign that causes problems in JSON keys as it is interpreted as a minus sign.

我刚刚测试了以下内容,它可以正常工作:

I just tested the below, it works:

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

这篇关于在空手道BDD中提取带有双引号的json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆