I want to query through some data from NewsAPI in React Native and have no idea how to do so and none of the tutorials I've seen have helped. Thanks!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Check out the Docs on Networking from React Native... I'm using Fetch in our production apps.
React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.
MDN Fetch API Guide
fetch('http://google.com')
.then(res => {
if (res.ok) return res.json())
else throw new Error(res)
.then(json => {
for (var key in json) {
// now you can parse it by calling json[key]
}
.catch(error => console.log(error)
}