第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何在 Go 中解組 Json 數(shù)組

如何在 Go 中解組 Json 數(shù)組

Go
慕碼人8056858 2022-07-11 14:46:47
我正在努力解析以下 json 數(shù)據(jù):[{"id":90129966,"from":"user@admin.com","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":"user@admin.com","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貢獻(xiàn)1824條經(jīng)驗 獲得超6個贊

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



查看完整回答
反對 回復(fù) 2022-07-11
  • 1 回答
  • 0 關(guān)注
  • 85 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號