A
A
AntonVirovets2018-02-26 17:38:18
JavaScript
AntonVirovets, 2018-02-26 17:38:18

How to get data from JSON?

Hello. Here is a link to the json file. https://api.myjson.com/bins/ftb79
How can I print this data to the console? I need to parse this url, but I don’t understand how ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Smykov, 2018-02-26
@AntonVirovets

Doing an XMLHttpRequest. If on the server - it's easier there. On the client cross-origin policy.
You take the contents of the file. Then you take responseText and do JSON.parse(xhr.responseText). The output is a complete array.
Working code for the client side

var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.myjson.com/bins/ftb79");
xhr.send();
console.log(JSON.parse(xhr.responseText));

Don't forget to mark my answer as the solution if it helped.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question