我有以下JSON响应,在测试中,我创建了一个要记录/捕获的键列表,但输出返回错误:类型错误:responseData.get不是函数,因为在解释“responseData.i”时作为字符串读取。
JSON response:
{
"Id": 1287,
"LastName": "Trump",
"FirstName": "Donald",
"MiddleName": "Von",
"City": "New York City",
"Phone": "66 77 88",
"State": "New York",
"Fax": "111-222-333",
"ReferenceId": "12345",
"Active": false,
"CurrentWorkingSchemeId": null
}
var responseData = pm.response.json()
var list_data = \["Id", "Fax", "Active"\];
for (i of list_data) {
console.log(responseData.Id, responseData.Fax, responseData.Active);
console.log(i, responseData.i);
console.log(i, responseData.get(i));
}
我需要做什么:响应数据.i =响应数据.Id不是响应数据.i =响应数据.“Id”
谢谢
1条答案
按热度按时间w8f9ii691#
正确的语法为
console.log(i, responseData[i]);