写一些可以读取此API Url的内容 [英] Write something that can read this 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)
});
这篇关于写一些可以读取此API Url的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文