javascript - Trying to load JSON via url in react-native but not getting correct response -


getdata() { return fetch("http://bitcfeedcms.rf.gd/script.php")   .then(response => {     console.log(response);     response.json();   })   .then(responsejson => {     this.setstate({ data: responsejson });   })   .catch(error => {     console.error(error);   }); 

}

i tried putting ?l=1 " bitcfeedcms.rf.gd/script.php?l=1 ". main json file " bitcfeedcms.rf.gd/feed_data.json ". tried "http://bitcfeedcms.rf.gd/feed_data.json?l=1" nothing changed

what have json data , use in app...please help

you using arrow function wrong. instead of this:

fetch("http://bitcfeedcms.rf.gd/script.php")   .then(response => {     console.log(response);     response.json();   })   .then(responsejson => {     this.setstate({ data: responsejson });   }) 

you should return response.json()

fetch("http://bitcfeedcms.rf.gd/script.php")    .then(response => {      console.log(response);      return response.json();    })    .then(responsejson => {      this.setstate({ data: responsejson });    }) 

this way can reach responsejson in next then.

also, if app complains fetch() network request failed it's info.plist or manifest configuration error. see topic.

for ios, can try same request https dummy json url: https://jsonplaceholder.typicode.com/posts/1


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -