【发布时间】:2019-12-22 04:01:17
【问题描述】:
我有一个邮递员 json 响应,并且在数组中特定变量的位置发生了变化。根据我在下面的回复,我需要编写一个测试来循环第一次看到 optionLabel 值为“2 Pax Min”的响应。 将其“id”,即 BBBB 保存在环境变量中
我试过了
var jsonData = JSON.parse(responseBody);
jsonData[[0].optionSet.options].forEach(function(arroption) {
if (arroption.optionLabel === '2 Pax Min') {
pm.environment.set("pax", JSON.stringify(arroption.id));
}
});
我的回应
[
{
"id": "",
"date": "2019-08-21",
"optionSet": {
"optionSetLabel": "Options",
"options": [
{
"id": "A",
"optionLabel": "QUAD Rm"
},
{
"id": "AA",
"optionLabel": "QUAD Rm with post Accom"
},
{
"id": "AAA",
"optionLabel": "Rm 3 Pax Min"
},
{
"id": "AAAA",
"optionLabel": "4 Pax Min"
}
]
}
},
{
"id": "",
"date": "2019-08-22",
"optionSet": {
"optionSetLabel": "Options",
"options": [
{
"id": "B",
"optionLabel": "QUAD Rm"
},
{
"id": "BB",
"optionLabel": "QUAD Rm with post Accom"
},
{
"id": "BBB",
"optionLabel": "SGL Rm with post Accom"
},
{
"id": "BBBB",
"optionLabel": "2 Pax Min"
}
]
}
}
]
我的最终结果是我想在环境变量中保存 id "BBBB"
【问题讨论】:
-
可以使用 javascript
标签: javascript arrays postman