我正在使用JSON將一些值從外部源獲取到變量中。我有一個(gè)像這樣的類型,json.Unmarshal將值放入: type Frame struct { Type string Value map[string]interface{} } var data Frame解組后,我可以通過以下方式訪問類型: data.Type但是,如果我嘗試執(zhí)行以下操作: if data.Type == "image" { fmt.Printf("%s\n", data.Value.Imagedata) }編譯器抱怨沒有這樣的值data.Value.Imagedata。所以我的問題是,我如何根據(jù)某些條件引用我知道會(huì)存在的Go屬性?做到這一點(diǎn): type Image struct { Filename string } type Frame struct { Type string Value map[string]interface{} }但這不是很靈活,因?yàn)槲覍⑹盏讲煌琕alue的。
具有未知屬性名稱的結(jié)構(gòu)的嵌套屬性?
繁星點(diǎn)點(diǎn)滴滴
2021-05-03 21:00:21