在空手道BDD中提取带有双引号的json数据 [英] Extract json data with double quotes in Karate BDD
问题描述
如何从下面的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: * urlhttps://xxx.yyy.com
Scenario:Get xxx-subject
Given pathxxx/oauth/internal/proof/srvc
And headerssomeData
When methodget
Then status200
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屋!