[英]Postman Script if else condition for null values
如果你確定jsonData
是一個數組,你可以檢查它的長度:
if (jsonData.length === 0) {
// ...
}
如果你不確定它是一個數組,你可以確保然后檢查它的長度:
if (Array.isArray(jsonData) && jsonData.length === 0) {
// ...
}
Comparing it with null
will always result in false
, because the variable jsonData
does not hold the value null
, it holds an array, which is an object, and thus different from null
.
您可以設置以下條件,因為它不是null
它是一個empty array
pm.test("Cases here", function () {
var jsonData = pm.response.json();
if (!jsonData || !jsonData.length) { # see condition here
console.log('1');
postman.setNextRequest("Get Count");
}
else {
console.log('2');
postman.setNextRequest("Create");
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.