我正在嘗試編譯以下代碼 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 關注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消