Golang中另一个结构内的结构数组

时间:2018-12-11 08:58:23

标签: arrays go struct

我是Utilities的新手,并尝试使用golang以这种格式创建json

golang

以下是我对{ "Title": "You are awesome", "Url": "www.youareawesome.com", "Desc": "your awesome desc is here", "Payment": { "Discount": "15%", "outlets": [ { "Location": "nowhere" }, { "Location": "everywhere" } ] } } 的代码

struct

这就是我正在做的

type Partner struct {
    Title   string `json:"Title"`
    URL     string `json:"Url"`
    Desc    string `json:"Desc"`
    Payment Payment `json:"Payment"`
}

type Payment struct {
    Discount string `json:"Discount"`
    outletList [] OutletItem `json:"outletList"`
} 

type OutletItem struct {
    Location string `json:"Location"`
}

我看不到付款对象中的出口阵列,我不确定是否错过了任何事情。

1 个答案:

答案 0 :(得分:4)

如果要导出此字段,

OutletList必须为大写

type Payment struct {
    Discount   string        `json:"Discount"`
    OutletList [] OutletItem `json:"outletList"`
}
相关问题