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

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

如何在 Go 中解組 Json 數組

如何在 Go 中解組 Json 數組

Go
慕碼人8056858 2022-07-11 14:46:47
我正在努力解析以下 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{[]}我不知道我在這里做錯了什么。有人能指出我正確的方向嗎?
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

從 Flimzy 那里得到了答案:var response []JsonTemplate。再次感謝。



查看完整回答
反對 回復 2022-07-11
  • 1 回答
  • 0 關注
  • 84 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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