function json_data () {
const url = "https://in.investing.com/economic-calendar/historical-data-table?eventId=201"
const res = UrlFetchApp.fetch(url,{muteHttpExceptions: true});
const data = JSON.parse(JSON.parse(res.getContentText));
const result = data.map(post => {
return [post["release_date"],post["actual"]]
})
return result
}
這是我第一次用編程語言撰寫,我在 Google-Sheet App-Script 中運行這個程式代碼。我收到的結果要么是空的,要么是未定義的,我什至不確定它是否是我請求的正確 JSON 檔案。我試圖請求的一段源 URL:
{"release_date":"Oct 24, 2022 (Oct)","time":"13:30","actual":"46.6","forecast":"47.8","previous":"48.4","metaData":{"timestamp":1666598400,"perliminary":true,"color":{"actual":"u-down","previous":""}
uj5u.com熱心網友回復:
改變這一行:
const data = JSON.parse(JSON.parse(res.getContentText));
至
const data = JSON.parse(JSON.stringify(res.getContentText()));
(你也可以JSON.parse(JSON.stringify())完全洗掉額外的)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/524238.html
上一篇:資料成行和列
