我正在努力解析以下 json 數據:[{"id":90129966,"from":"[email protected]","subject":"golang test","date":"2020-10-20 07:39:55"}]這是我的代碼:package mainimport ( "encoding/json" "fmt")type JsonTemplate struct { Id int `json:"id"` From string `json:"from"` Subject string `json:"subject"` Date string `json:"date"`}type Response struct { JsonTemplate []JsonTemplate}func main() { mockJson := `[{"id":90129966,"from":"[email protected]","subject":"golang test","date":"2020-10-20 07:39:55"}]` var response Response err := json.Unmarshal([]byte(mockJson), &response) if err != nil { fmt.Println(err) } fmt.Println(response)}輸出:json: cannot unmarshal array into Go value of type main.Response{[]}我不知道我在這里做錯了什么。有人能指出我正確的方向嗎?
如何在 Go 中解組 Json 數組
慕碼人8056858
2022-07-11 14:46:47