亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何解析字段名稱中具有隨機哈希值的golang json數組

如何解析字段名稱中具有隨機哈希值的golang json數組

Go
慕仙森 2023-06-01 15:03:03
我正在嘗試在 golang 代碼中從 API 解析 JSON。通過true選項參數傳遞它提供不同的附加信息和false不同的輸出。使用 Json to Go 轉換以獲得為此創建結構類型的幫助。但它為 json 示例提供了以下結構類型:{"result": {"99c4d91acc2486955c98015fbbdf06239b983c9d93d5069c39d040702af88738": {"size": 845,"fee": 0.000144,"time": 1547444481,"height": 1183405,"startingpriority": 89509.20245398773,"currentpriority": 89509.20245398773,"depends": []},"73f582cf419f8b1cd6a87f81e0e9a4e783add27c2be083361e8eb4a3bac0134e": {"size": 1635,"fee": 0.000312,"time": 1547444435,"height": 1183405,"startingpriority": 341863.3540372671,"currentpriority": 341863.3540372671,"depends": []}},"error": null,"id": "curltest"}type AutoGenerated struct {? ? Result struct {? ? ? ? Nine9C4D91Acc2486955C98015Fbbdf06239B983C9D93D5069C39D040702Af88738 struct {? ? ? ? ? ? Size? ? ? ? ? ? ?int? ? ? ? ? ?`json:"size"`? ? ? ? ? ? Fee? ? ? ? ? ? ? float64? ? ? ?`json:"fee"`? ? ? ? ? ? Time? ? ? ? ? ? ?int? ? ? ? ? ?`json:"time"`? ? ? ? ? ? Height? ? ? ? ? ?int? ? ? ? ? ?`json:"height"`? ? ? ? ? ? Startingpriority float64? ? ? ?`json:"startingpriority"`? ? ? ? ? ? Currentpriority? float64? ? ? ?`json:"currentpriority"`? ? ? ? ? ? Depends? ? ? ? ? []interface{} `json:"depends"`? ? ? ? }?}
查看完整描述

1 回答

?
撒科打諢

TA貢獻1934條經驗 獲得超2個贊

由于密鑰未知,因此您必須求助于動態數據結構。


定義單個元素,如:


type Element struct {

            Size             int           `json:"size"`

            Fee              float64       `json:"fee"`

            Time             int           `json:"time"`

            Height           int           `json:"height"`

            Startingpriority float64       `json:"startingpriority"`

            Currentpriority  float64       `json:"currentpriority"`

            Depends          []interface{} `json:"depends"`

}

然后將你的 json 解析成map[string]Element這樣:


result := make(map[string]Element)

json.Unmarshal(jsonBytes, &result)


查看完整回答
反對 回復 2023-06-01
  • 1 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號