【发布时间】:2021-09-02 08:35:53
【问题描述】:
我正在使用 Angular 来操作 tmdb api,但我无法获取数组内的项目,您能帮帮我吗? 数组返回给我的答案是这样的:
{
"id": 423108,
"results": [{
"id": "608177732da846006e382e45",
"iso_639_1": "en",
"iso_3166_1": "US",
"key": "qc6jN1BcJi0",
"name": "Official Trailer – Warner Bros. UK & Ireland",
"site": "YouTube",
"size": 1080,
"type": "Trailer"
}, {
"id": "6081f2879e45860058f36147",
"iso_639_1": "en",
"iso_3166_1": "US",
"key": "h9Q4zZS2v1k",
"name": "Official Trailer",
"site": "YouTube",
"size": 1080,
"type": "Trailer"
}, {
"id": "60a3f3d8cb75d1003f6cad3f",
"iso_639_1": "en",
"iso_3166_1": "US",
"key": "6Eb1V9gJ5Z4",
"name": "Chasing Evil Featurette",
"site": "YouTube",
"size": 1080,
"type": "Featurette"
}, {
"id": "60a7f244e16e5a003f89fcfb",
"iso_639_1": "en",
"iso_3166_1": "US",
"key": "4GjhydkUMrQ",
"name": "The Conjuring: The Devil Made Me Do It - Demonic Possession Featurette - Warner Bros. UK",
"site": "YouTube",
"size": 1080,
"type": "Featurette"
}, {
"id": "60b65a605c563400782c09c4",
"iso_639_1": "en",
"iso_3166_1": "US",
"key": "5FEdg3FhiGc",
"name": "Final Trailer – Warner Bros. UK & Ireland",
"site": "YouTube",
"size": 1080,
"type": "Trailer"
}, {
"id": "60b6e54aefd3c20041e08f6b",
"iso_639_1": "en",
"iso_3166_1": "US",
"key": "AB9mPsH2z1U",
"name": "The Conjuring: The Devil Made Me Do It | 2021 | Clip: "
Mitigating Circumstances " HD",
"site": "YouTube",
"size": 1080,
"type": "Clip"
}, {
"id": "60b9622aabf8e2006fb33499",
"iso_639_1": "en",
"iso_3166_1": "US",
"key": "tLFnRAzcaEc",
"name": "Final Trailer",
"site": "YouTube",
"size": 1080,
"type": "Trailer"
}, {
"id": "60be2d10960cde006d905ecf",
"iso_639_1": "en",
"iso_3166_1": "US",
"key": "2V2MmKkddM0",
"name": "The Conjuring: The Devil Made Me Do It - Teaser",
"site": "YouTube",
"size": 1080,
"type": "Teaser"
}]
}
我想得到“关键”项目。想法是获取密钥,然后将其与 youtube 链接连接以重定向到 youtube 上的预告片,或者将 youtube 播放器放入应用程序中。我目前正在这样做:
this.clientService.getVideoID(this.id).subscribe(data => this.video = date)
但是我只能访问video.results,不能给video.results.key
【问题讨论】:
-
这是因为 results 是一个对象数组,因此您需要通过
video.results[i].key访问,其中i是您希望访问的结果中对象的位置参数。
标签: javascript angular api