I have this code
request(options, (error, response) => {
const data = JSON.parse(response.body)
//console.log( JSON.stringify(data, null, " ") );
console.log(data);
})
Which gives me this output
{
result: 'OK',
data: {
body: {
pdpHeader: [Object],
overview: [Object],
hotelWelcomeRewards: [Object],
propertyDescription: [Object],
guestReviews: [Object],
atAGlance: [Object],
hotelBadge: [Object],
unavailable: {}
},
common: { pointOfSale: [Object], tracking: [Object] }
},
transportation: { transportLocations: [ [Object], [Object], [Object] ] },
neighborhood: { neighborhoodName: 'Manhattan' }
}
Within the actual body of this output there is this:
{4 items
"result":"OK"
"data":{2 items
"body":{14 items
"pdpHeader":{6 items
"hotelId":"424023"
"destinationId":"1506246"
"pointOfSaleId":"HCOM_US"
I want to call out the hotelID number: 424023
I have tried the following a few other modifications to this, but cannot seem to call out the correct object
console.log(data.body.pdpHeader.hotelID)
But I get the error message
console.log(data.body.pdpHeader.hotelID);
^
TypeError: Cannot read property 'pdpHeader' of undefined
data.data.body.... etc ... I assume the variable holding this object is calleddata... if it were calledgrahamyou'd usegraham.data.body... does that make sense now? can you see where you went wrong?