如何使用jsonPath过滤空手道dsl中的复杂响应?

我正在从REST API获得响应以下,但发现从接收到的响应中提取标签值并将其分配给变量以稍后在脚本中使用它很困难。
这是响应:

const date= currentitem.date;

我能够获得{ "result": "SUCCESS","rawAttr": "[{\"attributes\":[{\"name\":\"resourceid\",\"value\":\"7A7Q123456\"},{\"name\":\"physicalid\",{\"name\":\"dsw:label\",\"value\":\"MY Product00004285\"},{\"name\":\"dsw:created\",\"value\":\"2019-11-06T08:39:39Z\"}]}]","physicalid": "7A7Q123456","contextPath": "/path","id": "7A7Q123456","message": null } response.id,这对验证很有帮助,但是我却无法获得response.result的{​​{1}} dsw:label

当我执行value时,无论是数组还是字符串,我都得到以下值,我感到困惑。好像是一个字符串。

MY Product00004285

使用下面的JSON Path表达式在JMeter JSON Extractor中提取标签非常容易 def Arr = response.rawAttr

whfwt 回答:如何使用jsonPath过滤空手道dsl中的复杂响应?

请参阅空手道的类型转换功能:https://github.com/intuit/karate#type-conversion

因此您可以这样做:

* json attr = response.rawAttr

然后你们都准备好了。

,

感谢有关将字符串转换为json的示例和文档。
知道怎么做。

And def strVar = response.rawAttr
And json jsonVar = strVar
And def attrb = karate.jsonPath(jsonVar,'$..attributes.[2].value')[0]
And print '\n\n Attrb\n',attrb

我引用的链接:
Json Path evaluator
Karate doc reference for type conversion
Karate example for type-conversion

本文链接:https://www.f2er.com/3153753.html

大家都在问