How to query JSON data from REST API in React Nati

2019-06-11 03:20发布

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条回答
\"骚年 ilove
2楼-- · 2019-06-11 03:55

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)
 }
查看更多
登录 后发表回答