gpt4 book ai didi

karate - 如何在 Karate 中找到动态键值?

转载 作者:行者123 更新时间:2023-12-04 11:42:18 27 4
gpt4 key购买 nike

我正在点击 JIRA API 以根据周期名称获取周期 ID

API : http://localhost:8080/rest/zapi/latest/cycle?projectId=78654&versionId=123

我收到以下回复:

{

"1345": {
"totalExecutions": 0,
"endDate": "",
"description": "",
"versionName": "Unscheduled",
"projectKey": "ABC",
"totalDefects": 0,
"versionId": 123,
"name": "First cycle",
"totalFolders": 0,
"projectId": 78654
},
"5789": {
"totalExecutions": 0,
"endDate": "",
"description": "",
"versionName": "Unscheduled",
"projectKey": "ABC",
"totalDefects": 0,
"versionId": 123,
"name": "Karate DEMO",
"totalFolders": 0,
"projectId": 78654
},
"6543": {
"totalExecutions": 0,
"endDate": "",
"description": "",
"versionName": "Unscheduled",
"projectKey": "ABC",
"totalDefects": 0,
"versionId": 123,
"name": "Second Cycle",
"totalFolders": 0,
"projectId": 78654
},
"recordsCount": 3
}

这里的 Id 是动态的,即 1345,5789,6543

如何使用 Karate jsonpath 获取 ID,即 5789,其中名称为“Karate 演示”

最佳答案

使用 JSON 转换来更改形状,从而更容易执行 JsonPath。您还可以找到数据,因为 karate.forEach() 是一个“扫描”:https://github.com/intuit/karate#json-transforms

* def list = []
* def fun = function(k, v){ karate.appendTo('list', { key: k, val: v } )}
* karate.forEach(response, fun)
* def keys = $list[?(@.val.name=='Karate DEMO')].key

关于karate - 如何在 Karate 中找到动态键值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64639635/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com