我正在尝试从 golang 中的嵌套结构访问值。我的最终结构如下
StudentDetails = [{"rollno":3,"name":"John","score":{"sub1":50,"sub2":48,"sub3":45}} , {"rollno":4,"name":"James","score":{"sub1":38,"sub2":35,"sub3":40}}]
我想单独打印这些值。为此,我尝试添加一个循环
for i, details := range StudentDetails {
glog.Info("increment ", i)
glog.Info("name of student ", details.name)
glog.Info("mark of sub 1", details.score.sub1)
}
但我总是得到错误
"(type map[string]interface {} has no field or method name"" 我的结构如下
type scoreCard struct {
subject1 int `json:"id"`
subject2 int `json:"id"`
subject3 int `json:"id"`
}
type StudDetails struct {
roll int
name string
score scoreCard
}
呼唤远方
相关分类