javascript - Javascript - 获取
问题描述
我对编程很陌生,我遇到了一个问题。
这是我的代码:
fetch('https://feed.tunein.com/profiles/s9615/nowPlaying')
.then(response => response.json())
.then(data => console.log(data))
这是我得到的回复:
{
Header: { Title: 'Radio 1', Subtitle: 'BQL - Muza' },
Primary: {
GuideId: 's9615',
Image: 'http://cdn-radiotime-logos.tunein.com/s9615q.png',
Title: 'Radio 1',
Subtitle: 'Več dobre glasbe'
},
Secondary: {
GuideId: 'o0',
Image: 'http://cdn-radiotime-logos.tunein.com/s9615q.png',
Title: 'BQL - Muza',
Subtitle: 'Radio 1',
FullScreen: true
},
Ads: {
CanShowAds: true,
CanShowPrerollAds: true,
CanShowCompanionAds: false,
CanShowVideoPrerollAds: false
},
Echo: {
CanEcho: false,
EchoCount: 0,
TargetItemId: 's9615',
Scope: 's9615',
Url: '',
FeedTag: 's9615'
},
React: {
CanReact: false,
TargetItemId: 's9615',
Scope: 's9615',
Url: 'https://api.radiotime.com/profiles/me/activities?itemToken=BgwMAAAAAAAAAAAAAAABjyUAAAEMAY8lAAABjyUAAA',
Reactions: [ [Object], [Object], [Object], [Object], [Object] ]
},
Donate: { CanDonate: false },
Share: { CanShare: true, ShareUrl: 'http://tun.in/selA9' },
Follow: { Options: [ [Object], [Object] ] },
Record: { CanRecord: false },
Classification: {
ContentType: 'music',
IsEvent: false,
IsOnDemand: false,
IsFamilyContent: false,
IsMatureContent: false,
GenreId: 'g141'
},
Link: { WebUrl: 'http://www.radio1.si/' },
Ttl: 18,
Token: 'eyJwIjpmYWxzZSwidCI6IjIwMjAtMDQtMjRUMjM6NDA6MTAuNzIwNDY4OVoifQ'
}
所以我试图提取存储在Secondary - Title中的当前播放歌曲。那么我该如何提取它呢?
感谢您的帮助,也对我的英语感到抱歉,因为它不是我的第一语言!
解决方案
而不是console.log(data)
,通过使用访问标题console.log(data.Secondary.Title)
然后,您可能想要对数据做一些事情,而不是仅仅将其记录到控制台。
推荐阅读
- python - Python3 (Anaconda3) 和 Matplotlib 绘制指定的 x-ases 值
- corda - 交易是如何从 SignedTransaction 到 LedgerTransaction 的?
- java - TestNG 断言中的运行时问题
- javascript - 如何使用 *ngFor 迭代多维数组
- ios - 表视图单元格在引用它们的表视图被释放后不会被释放
- oracle - Oracle 10g 程序编译错误
- angular - 我在 Todos 项目期间遇到错误:http://localhost:4200/:404 Not Found 的 Http 失败响应
- r - 匹配来自两个不同数据集(dbSNP ID)的 col 值并合并数据集
- c - 向数组添加元素,旧值变为 0 但新显示
- javascript - WebGL 集成禁用输入字段