我正在尝试从github gist API获取文件名,下面的输出是我调用gist api.But时得到的,问题是我如何从输出中获取文件名。因为filename在files下,所以我想显示filename。那么我该怎么做呢。我是API的新手,所以只能显示url,id等。
{
"url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2",
"forks_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/forks",
"commits_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/commits",
"id": "41da54b03986886e1a4e57c8cdb38dc2",
"node_id": "MDQ6R2lzdDQxZGE1NGIwMzk4Njg4NmUxYTRlNTdjOGNkYjM4ZGMy",
"git_pull_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2.git",
"git_push_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2.git",
"html_url": "https://gist.github.com/41da54b03986886e1a4e57c8cdb38dc2",
"files": {
"telegram-white.svg": {
"filename": "telegram-white.svg",
"type": "image/svg+xml",
"language": "SVG",
"raw_url": "https://gist.githubusercontent.com/cmschandan/41da54b03986886e1a4e57c8cdb38dc2/raw/16b1aac41526997d87400f33ad9912d511faf7a4/telegram-white.svg",
"size": 1266
}
},
"public": true,
"created_at": "2020-12-11T12:58:59Z",
"updated_at": "2020-12-11T12:59:46Z",
"description": "",
"comments": 0,
"user": null,
"comments_url": "https://api.github.com/gists/41da54b03986886e1a4e57c8cdb38dc2/comments",
"owner": {
"login": "cmschandan",
"id": 21227329,
"node_id": "MDQ6VXNlcjIxMjI3MzI5",
"avatar_url": "https://avatars.githubusercontent.com/u/21227329?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/cmschandan",
"html_url": "https://github.com/cmschandan",
"followers_url": "https://api.github.com/users/cmschandan/followers",
"following_url": "https://api.github.com/users/cmschandan/following{/other_user}",
"gists_url": "https://api.github.com/users/cmschandan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/cmschandan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/cmschandan/subscriptions",
"organizations_url": "https://api.github.com/users/cmschandan/orgs",
"repos_url": "https://api.github.com/users/cmschandan/repos",
"events_url": "https://api.github.com/users/cmschandan/events{/privacy}",
"received_events_url": "https://api.github.com/users/cmschandan/received_events",
"type": "User",
"site_admin": false
},
"truncated": false
},发布于 2021-08-26 09:38:00
如果你使用的是JavaScript,那么你可以这样做:
// `getGitHubGist` is a function that I assume you already
// implemented which fetches your desired gist.
const gist = await getGitHubGist();
// Get an array of filename strings
const filenames = Object.keys(gist.files);
// Get an array of all the file details
const files = Object.values(gist.files);https://stackoverflow.com/questions/66385169
复制相似问题