J
J
JordanBelford2021-01-19 17:30:27
Node.js
JordanBelford, 2021-01-19 17:30:27

How to parse JSON response from server?

Good evening! I do not quite understand how to get the text field from json, can anyone tell me?

const requstURL = 'http://localhost:5000/main';

    const sendRequst = (method, url) => {
        return fetch(url).then(res => {
            return res.json()
        })
    }

    sendRequst("GET", requstURL).then(data => {
        let value = JSON.stringify(data)
     
    });

Received response from the server:
6006ed0077fe3237835765.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Zhivagin, 2021-01-19
@JordanBelford

So you have already parsed json in the res.json() line and for some reason again turn it into a JSON string through stringify :)

sendRequst("GET", requstURL).then(data => {
        data.forEach(item => {
            console.log(item.text);
        })
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question