gpt4 book ai didi

flutter - 我不明白如何从Dart中的API获取数据

转载 作者:行者123 更新时间:2023-12-03 04:53:53 26 4
gpt4 key购买 nike

我想从此api https://invidio.us/api/v1/search?q=获取视频标题和视频ID

例如,您搜索https://invidio.us/api/v1/search?q=tech+lead

然后你得到这个json。

[
{
"type": "video",
"title": "\"The Last Programmer\" (hacking the pandemic)",
"videoId": "heXI1pgQhvY",
"author": "TechLead",
"authorId": "UC4xKdmAXFh4ACyhpiQ_3qBw",
"authorUrl": "/channel/UC4xKdmAXFh4ACyhpiQ_3qBw",
"videoThumbnails": [...],
"description": "Ex-Google TechLead hacks into the viral pandemic. Check out http://coderpro.com/ for 100+ coding interview videos explained ...",
"descriptionHtml": "<div class=\"yt-lockup-description yt-ui-ellipsis yt-ui-ellipsis-2\" dir=\"ltr\">Ex-Google TechLead hacks into the viral pandemic. Check out <a href=\"http://coderpro.com/\" target=\"_blank\" title=\"http://coderpro.com/\" rel=\"nofollow\" dir=\"ltr\" class=\"yt-uix-redirect-link\">http://coderpro.com/</a> for 100+ coding interview videos explained ...</div>",
"viewCount": 58578,
"published": 1585252516,
"publishedText": "1 day ago",
"lengthSeconds": 447,
"liveNow": false,
"paid": false,
"premium": false
},
{...}, //other videos.
{...},
...]

我的目标是用dart / Flutter编写一个程序,该程序将获取每个视频标题及其对应的videoId并将其推送到列表中。

我尝试过在线搜索操作方法,但遇到了 https://flutter.dev/docs/cookbook/networking/fetch-data

但是对于我想做的事情来说似乎很复杂。我想知道是否存在更简单的方法。还考虑到我最多只需要搜索查询中的前8个视频。

最佳答案

我相信您是在说您不想创建一个类,因为您不需要它。即使不创建一个对象,您也可以避免它,尽管它可能更容易出错:

final result = await http.get('https://invidio.us/api/v1/search?q=tech+lead');
final data = json.decode(result.body);
data.forEach((e) {
print(e['title']);
print(e['videoId']);
});

关于flutter - 我不明白如何从Dart中的API获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60893355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com