我正在使用 postman 进行 API 测试。 我的回复信息是
[
{
"firstName": "Jia",
"lastName": "Tes",
"memberId": 745794,
"branchId": 12442,
"branchName": "NZ - Clubware Mobile Test Branch 1"
},
{
"firstName": "Jia",
"lastName": "Test2",
"memberId": 745746,
"branchId": 12442,
"branchName": "NZ - Clubware Mobile Test Branch 1"
},
{
"firstName": "Jia",
"lastName": "Test3",
"memberId": 745748,
"branchId": 12443,
"branchName": "Clubware Mobile Test Branch 2 (Pub)"
},
{
"firstName": "Jia",
"lastName": "Test3",
"memberId": 745745,
"branchId": 12442,
"branchName": "NZ - Clubware Mobile Test Branch 1"
}
]
我想得到 "memberId"where "firstName": "Jia","lastName": "Test3"and "branchName": "NZ - Clubware Mobile Test Branch 1"
我现在的代码是这样的
var response = JSON.parse(responseBody);
console.log("BODY:" + response[3].memberId);
但是我不喜欢使用索引来定位列表中的元素,我该怎么做,谢谢大家!!
最佳答案
如果您只想检查特定值,可以使用 _.find() Lodash函数获取memberId
值:
var user = _.find(pm.response.json(), {
firstName: "Jia",
lastName: "Test3",
branchName: "NZ - Clubware Mobile Test Branch 1"
})
console.log(user.memberId)
关于javascript - 从 json 列表中获取特定值在 postman 测试中使用 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50848091/