如何在POSTMAN

时间:2016-11-18 12:35:39

标签: json postman

要检查Respondy Body是否有字符串,我可以使用:

tests["Body matches string"] = responseBody.has("string_you_want_to_search");

但我有一个像这样的回应:

{  
 "total": 20000,
 "amount": {
   "total": 10000,
   "fees": 0,
   "refunds": 0,
   "liquid": 10000,
   "currency": "BRL"
 },
}

如何查看字段amount.total?

1 个答案:

答案 0 :(得分:0)

使用点运算符进行测试以访问嵌套值:

var data = JSON.parse(responseBody);
tests["10000"] = data.amount.liquid === "10000";
tests["BRL"] = data.amount.currency === "BRL";

希望它有所帮助!