gpt4 book ai didi

json - postman jetpacks - 测试嵌套数据

转载 作者:行者123 更新时间:2023-11-28 19:48:46 25 4
gpt4 key购买 nike

我在 postman 中进行了测试,响应返回“嵌套”数据。我的意思是我们有响应的“数据”部分和“消息”部分。数据内部还有大量其他字段,这些是我需要使用 Jetpacks 验证的字段。我怎样才能到达这些字段?

这是 json 响应的样子:

{
"Data": {
"QRCode_ID": 168,
"Repairer_ID": null,
"AssignedToEmployee_ID": null,
"TaskName": "003021919913",
"DueDate": "2015-07-02T00:12:53.597",
"DueDateTimeSpan": 1959471956224,
"TaskStatus_ID": 1,
"Description": "due 6/30, 5:00",
"TaskUrgency_ID": null,
"TaskType_ID": null,
"DueDateDisplay": "2015-07-02 00:12",.......
}
},
"Messages": [
"success"
]
}

这就是我的 postman 测试的样子:

var data = JSON.parse(responseBody);
tests["Verify QRCode_ID is correct"] = data.QRCode_ID === 168;

最佳答案

您可以使用与测试非嵌套数据(使用点表示法)相同的方式来测试嵌套数据

我创建了一个非常快速的虚拟服务,它返回以下 json:

{
"one": "1",
"two": "2",
"three": {
"four": "4",
"five": "5"
}
}

在下面的代码片段中,我测试(使用点表示法)嵌套对象中的值。特别是,我断言对象 3 的属性 4 和 5 分别设置为“4”和“5”的值:

var data = JSON.parse(responseBody);
tests["4"] = data.three.four === "4";
tests["5"] = data.three.five === "5";

这是我在 postman 中的设置以及相应的 json 响应:enter image description here

这是我的测试结果: enter image description here

关于json - postman jetpacks - 测试嵌套数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31161571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com