Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i get json in axios with react native?

I’m trying to get json in axios

but if i use my code this error and warning occured

How can i get response.json ??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

response.json is not a function

this is my code

      //    url="https://yts.lt/api/v2/list_movies.json?sort_by=like_count&order_by=desc&limit=5"
            
            url is props

     useEffect(() => {
        axios
          .get(url)
          .then((response) => response.json())
          .then((json) => {
            console.log('json', json);
            setData(json.data.movies);
          })
          .catch((error) => {
            console.log(error);
          });
      }, []);

>Solution :

Use this:

useEffect(() => {
        axios
          .get(url)
          .then((response) => response.data)
          .then((json) => {
            console.log('json', json);
            setData(json.data.movies);
          })
          .catch((error) => {
            console.log(error);
          });
      }, []);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading