【发布时间】:2022-01-31 00:29:15
【问题描述】:
我想在我的网站中实现这个 API,这样我就可以从 reddit 中获取随机模因。
API 由 D3vd 在 github (https://www.github.com/D3vd/Meme_API) 上制作
我从https://meme-api.herokuapp.com/gimme/memes(api)得到的响应是这样的:
{
"postLink": "https://redd.it/sg8j7b",
"subreddit": "memes",
"title": "No you respect the nature now!",
"url": "https://i.redd.it/nk9eiy1nnte81.jpg",
"nsfw": false,
"spoiler": false,
"author": "Abdul_Sbeei",
"ups": 423,
"preview": ["https://preview.redd.it/nk9eiy1nnte81.jpg?width=108\u0026crop=smart\u0026auto=webp\u0026s=253fc41547e5acc1ee3efcc0a4644e8d52d67181", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=216\u0026crop=smart\u0026auto=webp\u0026s=6050660429dd3a4ae6699a0f42294c04fc1fae02", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=320\u0026crop=smart\u0026auto=webp\u0026s=07ff549bbd76d2f25f509cece0149e7939427edd", "https://preview.redd.it/nk9eiy1nnte81.jpg?width=640\u0026crop=smart\u0026auto=webp\u0026s=baa9e058ba9722515aefa9ab28bb95235d0e151b"]
}
如何使用 javascript 仅获取图片链接(“url”),以便将其显示在我的网站上?
提前谢谢
【问题讨论】:
-
yourResponseObject.url... -
在 Javascript 中,使用 obj.key 访问键 例如 let obj = {a: 'test'};控制台日志(obj.a); // 这将打印 test 如果你的 API 响应,你可以说 obj.url
-
请显示您用于获取 API 数据的代码
-
我通过访问 url 得到了输出
标签: javascript html json