【发布时间】:2021-11-07 04:02:07
【问题描述】:
我正在尝试从 json 对象中获取单个值。例如,只获取“作者”而不是整个对象
这是我当前的代码:
const getArticlesFromApi = async () => {
let response = await fetch(
'http://api.mediastack.com/v1/news'
)
let test = await response.json();
console.log(test)
}
可以对上面的代码做些什么来达到我想要的结果 这是当前的输出:
Object {
"author": "OdAdmin",
"category": "general",
"country": "us",
"description": "New Delhi: Overcoming all hurdles and finding new solutions, Indian Railways is continuing its journey of bringing relief by delivering Liquid Medical Oxygen(LMO) to various states across the country. Oxygen Expresses crossed mark of 26000 MT of LMO delivery in service to the Nation. So far, Indian Railways has delivered more than 26891 MT of […]",
"image": null,
"language": "en",
"published_at": "2021-06-07T15:37:44+00:00",
"source": "orissadiary",
"title": "Oxygen Expresses deliver more than 26891 MT of LMO to the Nation",
"url": "https://orissadiary.com/oxygen-expresses-deliver-more-than-26891-mt-of-lmo-to-the-nation/",
},
Object {
"author": "Graham Gremore",
"category": "general",
"country": "us",
"description": "We've officially lost count of how many times Rand Paul has claimed to be the victim of some sort of foiled assassination plot.",
"image": null,
"language": "en",
"published_at": "2021-06-07T15:39:05+00:00",
"source": "queerty",
"title": "Rand Paul claims his life is in danger (again), says “I don’t know what the world’s coming to!”",
"url": "https://www.queerty.com/rand-paul-claims-life-danger-says-dont-know-worlds-coming-20210607",
},
【问题讨论】:
标签: javascript json react-native