How to decode json into structs

后端 未结 3 1216
既然无缘
既然无缘 2021-02-08 00:21

I\'m trying to decode some json in Go but some fields don\'t get decoded. See the code running in browser here:

What am I doing wrong?

I need only the MX reco

3条回答
  •  粉色の甜心
    2021-02-08 01:21

    You must Uppercase struct fields:

    type MxRecords struct {
        Value    string `json:"value"`
        Ttl      int    `json:"ttl"`
        Priority int    `json:"priority"`
        HostName string `json:"hostName"`
    }
    
    type Data struct {
        MxRecords []MxRecords `json:"mxRecords"`
    }
    

    http://play.golang.org/p/EEyiISdoaE

提交回复
热议问题