這是我的第一個(gè)問題,所以歡迎每一個(gè)建議。目前,我正在使用 Go 開發(fā)一個(gè)小型項(xiàng)目,該項(xiàng)目處理來自 Web 上的 API 的股票數(shù)據(jù)。我在從那里解析一些 JSON 數(shù)據(jù)時(shí)遇到問題。JSON 看起來像這樣:{ "Meta Data": { "1. Information": "Daily Time Series with Splits and Dividend Events", "2. Symbol": "IBM", "3. Last Refreshed": "2020-11-13", "4. Output Size": "Full size", "5. Time Zone": "US/Eastern" }, "Time Series (Daily)": { "2020-11-13": { "1. open": "115.1900", "2. high": "117.3700", "3. low": "115.0100", "4. close": "116.8500", "5. adjusted close": "116.8500", "6. volume": "4683512", "7. dividend amount": "0.0000", "8. split coefficient": "1.0" }, "2020-11-12": { "1. open": "115.6300", "2. high": "116.3700", "3. low": "113.4800", "4. close": "114.5000", "5. adjusted close": "114.5000", "6. volume": "6500799", "7. dividend amount": "0.0000", "8. split coefficient": "1.0" }, ...我對(duì)元數(shù)據(jù)不感興趣,只對(duì)時(shí)間序列(每日)鍵感興趣。問題是,這不是一個(gè)數(shù)組,而是一個(gè)包含多個(gè)結(jié)構(gòu)的結(jié)構(gòu)。我有一個(gè)鏡像時(shí)間序列(每日)鍵中的字段的結(jié)構(gòu),并希望將時(shí)間序列(每日)鍵轉(zhuǎn)換為我的結(jié)構(gòu)數(shù)組,以便我可以處理數(shù)據(jù)。我已經(jīng)找到了一些與我的問題相似的帖子,但它們都有一個(gè) JSON 數(shù)組,這里不存在。我嘗試使用 Go 的 JSON-Library 自己做,但沒有成功。
1 回答

呼如林
TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
您可以使用這樣的結(jié)構(gòu):
type Daily struct {
Open string `json:"1. open"`
...
}
type Data struct {
TimeSeries map[string]Daily `json:"Time Series (Daily")`
}
- 1 回答
- 0 關(guān)注
- 96 瀏覽
添加回答
舉報(bào)
0/150
提交
取消