我试图从服务器的响应正文中提取数据。我浏览了一段时间的互联网,发现了一些“应该”起作用的东西,但没有。该请求是一个返回JSON对象的https请求。从包含数组的JSON对象提取数据
//Open the request:
request({
//Set the request Method:
method: 'POST',
//Set the headers:
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer "+ token,
'X-Originating-Ip': ipAddress
},
//Set the URL:
url: 'URL',
//Set the request body:
body: { 'Body here'},
}, function(error, response, body){
//Alert the response body:
for(var i=0; body.data.listings.length; i++){
console.log(data.listings[i].listingType);
}
console.log(response.statusCode);
});
出于安全原因,我不能显示实际的响应体,但它是一个包含多个阵列JSON对象。
我仍然得到一个TypeError:无法读取未定义的属性'列表' –
@ChristopherLittlewood这意味着'body'对象没有'data'属性。尝试使用'console.log(JSON.stringify(body))'进行打印调试 – shawon191