【发布时间】:2017-03-16 01:05:27
【问题描述】:
我想在 React Native 中从 NewsAPI 中查询一些数据,但不知道该怎么做,而且我看到的教程都没有帮助。谢谢!
【问题讨论】:
-
看看:stackoverflow.com/help/how-to-ask 你会更幸运地得到问题的答案
标签: json http reactjs react-native
我想在 React Native 中从 NewsAPI 中查询一些数据,但不知道该怎么做,而且我看到的教程都没有帮助。谢谢!
【问题讨论】:
标签: json http reactjs react-native
查看Docs 上的来自 React Native 的网络...我正在我们的生产应用程序中使用 Fetch。
React Native 为您的网络需求提供了 Fetch API。如果您以前使用过 XMLHttpRequest 或其他网络 API,那么 Fetch 看起来会很熟悉。您可以参考 MDN 的使用 Fetch 指南了解更多信息。
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)
}
【讨论】:
<Text/> 组件中。