【发布时间】:2018-08-07 22:38:42
【问题描述】:
我正在尝试断言并打印响应,因为需要帮助。
以下是响应正文:
{
"createdIncidents":[
{
"incidentRef":"I0000000",
"personName":"API API",
"personType":"Patient"
},
{
"incidentRef":"I0000000",
"personName":"Ballarat HelpDesk",
"personType":"Staff"
},
{
"incidentRef":"I0000000",
"personName":"test api",
"personType":"Visitor"
},
{
"incidentRef":"I0000000",
"personName":null,
"personType":"Hazard"
}
]
}
我正在尝试将incidentRef 和personType 一起打印在一个字符串中。
为此,我正在使用以下代码:
var data = JSON.parse(responseBody);
data.createdIncidents.forEach(function(incident, personT) {
var personType = "personType" + personT.personType;
var incidents = "incidentRef" + incident.incidentRef;
var pt = tests["incidents created for " + personType ] = 'personType';
var inc = tests["incidents number is " + incidents] = 'incidents';
tests["incidents created for" +inc && + pt ];
});
这里没有读取函数内的第二项。
在单独的函数声明中它工作正常。
我想打印成:
"incidentRef": "I0000000 is created for "personType": "Hazard""
【问题讨论】:
-
回答这个问题真的很令人困惑 - 你只想注销
personType和incidentRef吗?你想检查什么? -
我想断言响应并将其显示为 "incidentRef": "I0000000 is created for "personType": "Hazard" ,用于上面给出的响应
-
我已更新我的答案以打印出您想要的内容。