サーバーからレスポンス本文からデータを抽出しようとしています。私はしばらくの間、インターネットを閲覧し、 "うまくいくはず"ということをいくつか見つけましたが、そうではありません。リクエストは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