Answer the question
In order to leave comments, you need to log in
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
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));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question