邮递员测试 - JSON - 使用具有不同值的重复键迭代响应 [英] Postman Testing - JSON - iterate over response with duplicate keys with different values

查看:59
本文介绍了邮递员测试 - JSON - 使用具有不同值的重复键迭代响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是邮递员测试的新手,我发现了这个案例.我有这个回复

I'm new to the postman testing and i have found this case. I have this response

{
    "company": [
        {
            "publicKey": "40",
            "mutkey": "13273811",
            "employee": [
                {
                    "publicKey": "3030",
                    "mutkey": "13415424",
                    "formattedName": "V Vierde",
                    "contract": [
                        {
                            "publicKey": "1",
                            "mutkey": "13415424",
                            "functionName": "***NO FUNCTION NAME FOUND***"
                        }
                    ]
                },
                {
                    "publicKey": "3040",
                    "mutkey": "13415426",
                    "formattedName": "V Vijfde",
                    "contract": [
                        {
                            "publicKey": "1",
                            "mutkey": "13415426",
                            "functionName": "***NO FUNCTION NAME FOUND***"
                        }
                    ]
                }
            ]
        }
    ]
}

我需要收集,f.e.一个数组,键函数名的每个值.Postman 有没有办法做到这一点?

I need to get into collection, f.e. an Array, every value for key functionName. Is there a way in Postman to do that?

推荐答案

有了这个你可以得到每个functionName:

With this you can get each functionName:

const resBody = pm.response.json();

let employees = resBody.company[0].employee

let numberOfEmployees = employees.length

for (var i = 0; i < numberOfEmployees; i++){
    let functionName = employees[i].contract[0].functionName;
    console.log(functionName);
    // your code here
}

这篇关于邮递员测试 - JSON - 使用具有不同值的重复键迭代响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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