如何仅从API JSON响应数据中获取某些数据
我是JS和JSON的新手,我看了一段时间,似乎找不到答案。我试图使用此API,该API返回两个属性,如下面的代码块中所示,
{
"quote": "Innovation distinguishes between a leader and a follower.",
"name": "Steve Jobs"
}
它仅返回这两个值,并且每次都会随机化。使用JS,我每次仅抓取“引用”元素。 提前致谢!
I am very new to JS and JSON, I've looked for a while and I can't seem to find the answer. I'm trying to use this API that returns two properties, as seen in the code block below,
{
"quote": "Innovation distinguishes between a leader and a follower.",
"name": "Steve Jobs"
}
It only returns those 2 values and they are randomized each time. Using JS, how do I only grab the "quote" element each time.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例
输出
创新区分领导者和追随者。
编辑:
无法实际从您的网站获取
我
数据
现在,由于CORS,
将 从API获取数据,然后您可以做您想做的事
example
output
Innovation distinguishes between a leader and a follower.
Edit:
Now I won't be able to actually get the data from your website due to CORS
but you could use the fetch method for it
example
and then you can use the above method to get the quote from it
this will on document load, fetch the data from API and then you can do what you want with it