1 回答

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)
}
- 1 回答
- 0 關注
- 123 瀏覽
添加回答
舉報