我有如下的React体:`
{
"timestamp": "2022-11-08T12:40:11.631Z",
"data": {
"version": "2.2",
"endpoints": [
{
"identifier": "credentials",
"role": "SENDER",
"url": "https://example.com/credentials65"
},
{
"identifier": "tokens",
"role": "RECEIVER",
"url": "https://example.com/tokens245"
},
{
"identifier": "tokens",
"role": "SENDER",
"url": "https://example.com/tokens353"
},
.......
对于每个标识符和角色(在Postman测试会话中),我希望自动定义变量。
我尝试了以下的第一个:
_.each(pm.response.json(), (responseBody) => {
if (responseBody.identifier['data'][1]['identifier'] === "credentials") {
pm.globals.set("credentials_url", responseBody.url)
}
else if (responseBody.identifier === "tariffs") {
pm.globals.set("tariffs_url", responseBody.url)
}
})
问题是我不知道如何调用“标识符”,脚本没有进入if循环。有人能帮助吗?
1条答案
按热度按时间uinbv5nw1#
您可以使用
pm.globals.get("tariffs_url")
、pm.globals.get("credentials_url")
等访问数组中的URL(它适用于每个标识符)