亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

未定義(類型 []DataReponse 沒有字段或方法)

未定義(類型 []DataReponse 沒有字段或方法)

Go
ITMISS 2022-01-17 16:52:35
我正在嘗試編譯以下代碼    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" {

         ...   

        }

    }


查看完整回答
反對 回復 2022-01-17
?
慕斯709654

TA貢獻1840條經驗 獲得超5個贊

[]DataReponseDataReponses 的一部分,即可能有多個響應(或沒有響應)。您可以使用for 循環為每個struct DataReponse返回的代碼運行一些代碼。我會考慮做巡回演出。(另外,也許您的意思是 DataResponse,帶有兩個“s”,但當然,只要您始終使用相同的名稱,這對 Go 并不重要。)


查看完整回答
反對 回復 2022-01-17
  • 2 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號