首页 > 解决方案 > 如何在邮递员中验证 JSON 数组值?

问题描述

{
    "success": {
        "text": "successfully! deleted Records"
    }
}

想要验证文本值是“成功!删除记录”

我试过这个

pm.test("Your test name", function () {
    var jsonData = pm.response.json();

    pm.expect(jsonData[0].text).to.eql("successfully! deleted Records");
});

标签: postmanweb-api-testingpostman-testcase

解决方案


您正在尝试从 JSON 对象而不是数组中检索数据。因此,它应该如下。

pm.test("Your test name", function () {
    var jsonData = pm.response.json();    
    pm.expect(jsonData.success.text).to.eql("successfully! deleted Records");
});

推荐阅读