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

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

具有許多嵌套的結構填充錯誤

具有許多嵌套的結構填充錯誤

Go
躍然一笑 2023-06-05 19:29:07
我不明白錯誤在哪里,因為在完成結構后,在我看來undefined: Payload這是一個非常煩人的結構,因為它有足夠的結構嵌套和結構切片你能幫我解決這個問題嗎,因為我無法解決它?https://play.golang.org/p/QewpCfTWY0lpackage mainimport (    "fmt")type DialogFlowResponseSuggestion struct {    Payload struct {        Google struct {            ExpectUserResponse bool `json:"expectUserResponse"`            RichResponse       struct {                Items []struct {                    SimpleResponse struct {                        TextToSpeech string `json:"textToSpeech"`                    } `json:"simpleResponse"`                } `json:"items"`                Suggestions []struct {                    Title string `json:"title"`                } `json:"suggestions"`            } `json:"richResponse"`        } `json:"google"`    } `json:"payload"`}func main() {    in := DialogFlowResponseSuggestion{        Payload: Payload{            Google: Google{                ExpectUserResponse: true,                RichResponse: RichResponse{                    Items: []Items{                        Items{SimpleResponse: SimpleResponse{dialog.MReturn.Message}},                    },                    Suggestions: []Suggestions{                        Suggestions{Title: "Suggestion Chips"},                        Suggestions{Title: "suggestion 1"},                        Suggestions{Title: "suggestion 2"},                    },                },            },        },    }    fmt.Println(in)}
查看完整描述

1 回答

?
慕娘9325324

TA貢獻1783條經驗 獲得超4個贊

你的 internalstruct沒有在任何地方聲明——它們都是匿名類型。要按名稱實際顯式實例化它們,它們需要存在于某個地方(操場):


package main


import (

    "fmt"

)


type SimpleResponse struct {

    TextToSpeech        string          `json:"textToSpeech"`

}


type Item struct {

    SimpleResponse      SimpleResponse  `json:"simpleResponse"`

}


type Suggestion struct {

    Title               string          `json:"title"`

}


type RichResponse struct {

    Items               []Item          `json:"items"`

    Suggestions         []Suggestion    `json:"suggestions"`

}


type Google struct {

    ExpectUserResponse  bool            `json:"expectUserResponse"`

    RichResponse        RichResponse    `json:"richResponse"`

}


type Payload struct {

    Google              Google          `json:"google"`

}


type DialogFlowResponseSuggestion struct {

    Payload             Payload         `json:"payload"`

}


func main() {

    in := DialogFlowResponseSuggestion{

            Payload: Payload{

                Google: Google{

                    ExpectUserResponse: true,

                    RichResponse: RichResponse{

                        Items: []Item{

                            Item{SimpleResponse: SimpleResponse{dialog.MReturn.Message}},

                        },

                        Suggestions: []Suggestion{

                            Suggestion{Title: "Suggestion Chips"},

                            Suggestion{Title: "suggestion 1"},

                            Suggestion{Title: "suggestion 2"},

                        },

                    },

                },

            },

        }


    fmt.Println(in)

}


查看完整回答
反對 回復 2023-06-05
  • 1 回答
  • 0 關注
  • 123 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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