我正在尝试编译以下代码 var result []DataReponse if result.Commenter == "teacher"{ sender = models.CommentUser{ Name:result.UserName, Email:result.UserEmail, } }else{ sender = models.CommentUser{ Name:result.ChildName, Email:result.ChildEmail, }我在result.Commenter undefined (type []DataReponse has no field or method Commenter)这里收到错误是我的结构//DataReponse is the structure of the responsetype DataReponse struct{ CommentText string `json:"comment_text"` Commenter string `json:"commenter"` ChildEmail core.NullString `json:"child_email"` ChildName core.NullString `json:"child_name"` UserName core.NullString `json:"user_name"` UserEmail core.NullString `json:"user_email"`}我如何使用结果值?
2 回答

慕田峪9158850
TA贡献1794条经验 获得超8个赞
正如 twotwotwo 所解释的,您正在使用切片。像这样循环它。
for _, data := range result {
if data.Commenter == "teacher" {
...
}
}
- 2 回答
- 0 关注
- 174 浏览
添加回答
举报
0/150
提交
取消