我试图获取https://api.llama.fi/charts/Ethereum给出的数据
看起来像是
[{“日期”:“1546560000”、"totalLiquidityUSD":273845651.27077854}、{“日期”:“1546646400”、"totalLiquidityUSD":288674544.41292274}、{“日期”:“1546732800”、"totalLiquidityUSD":297321259.6930144}、{“日期”:“1546819200”、"totalLiquidityUSD":286168221.103729}、{“日期”:“1546905600”、"totalLiquidityUSD":285073686.76345384}
当我用铬打开它的时候。
在使用urllib.request.urlopen()的python中,它工作得很好。
在Google单子里,我试着
function myFunction() {
var data = UrlFetchApp.fetch("https://api.llama.fi/charts/Ethereum").getResponseCode()
var data2 = UrlFetchApp.fetch("https://api.llama.fi/charts/Ethereum").getContentText()
console.log(UrlFetchApp.fetch("https://api.llama.fi/charts/Ethereum").getContentText())
}
这里的数据= 200,但data2 =未定义。我认为这是一个新手的问题,但我不熟悉JS或GS。
谢谢你的帮忙!
最好的
多米尼克
发布于 2021-11-02 16:13:37
通过将ContentText解析为JSON,您可以以JSON对象的形式访问数据,然后可以使用for迭代数据,或者以任何需要的方式使用它。
function myFunction() {
var response = UrlFetchApp.fetch("https://api.llama.fi/charts/Ethereum").getContentText()
var data = JSON.parse(response);
for(const d of data) {
console.log("DATE: " + d.date)
console.log("LIQUIDITY: " + d.totalLiquidityUSD)
}
}
https://stackoverflow.com/questions/69813226
复制相似问题