写一些可以读取这个API Url的东西

写一些可以读取这个API Url的东西

问题描述:

如何读取此 API 并从中获取信息?到 JavaScript.

How can I read this API and get information from it? to javascript.

https://bitcoinfees.earn.com/api/v1/fees/recommended

this does not seem to work - 
loadJSON("https://bitcoinfees.earn.com/api/v1/fees/recommended", gotData, 'jsonp');

function gotData(data) {
  println(data);
}

loadJSON 不是原生 JS 函数(它在库 p5 中).您可以像这样使用 fetch 函数:

loadJSON is not a native JS function(it is in library p5). You can use the fetch function like this:

    fetch("https://bitcoinfees.earn.com/api/v1/fees/recommended") // Call the fetch function passing the url of the API as a parameter
    .then((resp) => resp.json()) // Transform the data into json
    .then(function(data) {
        // Your code for handling the data you get from the API
    	console.log(data);
        console.log(data.fastestFee); //And since it is just an object you can access any value like this
    })
    .catch(function(err) {
        // This is where you run code if the server returns any errors (optional)
    	console.log(err)
    });