我正在使用 TomTom places api 作为项目的一部分。我是 Javascript 新手,我发现很难从 API 中提取我需要的信息。我正在尝试从结果数组中获取所有姓名、电话号码、地址和网址。这就是我正在使用的 -
"summary": {
"query": "restaurant",
"queryType": "NON_NEAR",
"queryTime": 126,
"numResults": 10,
"offset": 0,
"totalResults": 102131,
"fuzzyLevel": 1,
"geoBias": {
"lat": 50.266,
"lon": 5.0527
}
},
"results": [{
"type": "POI",
"id": "GB/POI/p0/1035734",
"score": 2.1523399353027344,
"dist": 277294.490777698,
"info": "search:ta:826009007710588-GB",
"poi": {
"name": "Bay Restaurant",
"phone": "+(44)-(1304)-852229",
"categorySet": [{
"id": 7315008
}],
"url": "thewhitecliffs.com",
"categories": [
"british",
"restaurant"
],
"classifications": [{
"code": "RESTAURANT",
"names": [{
"nameLocale": "en-US",
"name": "restaurant"
},
{
"nameLocale": "en-US",
"name": "british"
}
]
}]
},
"address": {},
"position": {
"lat": 51.15375,
"lon": 1.37204
},
"viewport": {
"topLeftPoint": {
"lat": 51.15465,
"lon": 1.37061
},
"btmRightPoint": {
"lat": 51.15285,
"lon": 1.37347
}
},
"entryPoints": [{
"type": "main",
"position": {
"lat": 51.15375,
"lon": 1.37204
}
}]
}
到目前为止,我已经设法通过以下方式获得结果第一名的名称 -
function callbackFn(result) {
console.log(result[0].poi.name)
}
我已经设法对电话号码做同样的事情 -
function callbackFn(result) {
console.log(result[0].poi.phone)
}
但是,我不知道如何获取所有给定结果的数据。给出的结果数量取决于搜索条件,所以我希望能够获得所有结果的名称、电话号码、地址和网址,无论是 8 还是 100。