Yu *_*Jia 2 javascript json 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"
}
]
Run Code Online (Sandbox Code Playgroud)
我想得到“memberId”,其中“firstName”:“Jia”、“lastName”:“Test3”和“branchName”:“NZ - Clubware Mobile Test Branch 1”
我目前的代码就像
var response = JSON.parse(responseBody);
console.log("BODY:" + response[3].memberId);
Run Code Online (Sandbox Code Playgroud)
但我不喜欢使用索引来定位列表中的元素,我该怎么做,谢谢你们!!
如果你只是想检查一个特定的值,你可以使用_.find() Lodash 函数来获取memberId值:
var user = _.find(pm.response.json(), {
firstName: "Jia",
lastName: "Test3",
branchName: "NZ - Clubware Mobile Test Branch 1"
})
console.log(user.memberId)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4638 次 |
| 最近记录: |