我是 Golang 的新手,我需要知道如何从格式的结构中访问值:type CurrentSkuList struct { SubscriptionNumber string `json:"subscriptionNumber` Quantity int `json:"quantity"` SubscriptionProducts []struct { ID int `json:"id"` ActiveStartDate int `json:"activeStartDate"` ActiveEndDate int `json:"activeEndDate"` Status string `json:"status"` Sku string `json:"sku"` ChildIDs []int `json:"childrenIds"` } `json:"subscriptionProducts"`}例如,如果我有一个currentSkus类型的变量CurrentSkuList并且我只需要访问Sku和Status值,有没有办法做类似的事情:currentSkus.SubscriptionProducts.Sku?编辑!当我尝试访问时currentSkus.Quantity出现编译器错误undefined (type []util.CurrentSkuList has no field or method Quantity)。
1 回答

紫衣仙女
TA贡献1839条经验 获得超15个赞
是的,有办法。您可以通过.
您建议的语法访问。在这种情况下,CurrentSkuList 返回 SubscriptionProduct 的一个片段,你知道这是因为这[] struct
部分。然后你将不得不以这种方式访问数据:
currentSkus.SubscriptionProducts[index].Sku
- 1 回答
- 0 关注
- 130 浏览
添加回答
举报
0/150
提交
取消