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

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

json.unmarshal() - 返回零

json.unmarshal() - 返回零

Go
LEATH 2021-09-13 15:11:20
我從基本切片(由 json.Marshal 制作的切片)獲取一個字節的正常切片并嘗試解碼它們,但是 json.unmarshal() - 返回 nil代碼 :coded := redis.LoadFromBase()uncoded := json.Unmarshal(coded, &p)fmt.Println("Bytes:", coded)fmt.Println("Unmarshalled:", uncoded)回來:Bytes: [123 34 84 105 116 108 101 34 58 34 97 34 44 34 67 111 110 116 101 110 116 34 58 34 98 34 125]Unmarshalled: <nil>LoadFromBase() 工作正常
查看完整描述

1 回答

?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

您正在打印json.Unmarshal不是實際解碼值返回的錯誤。正是nil如此,一切都很好。


它應該是:


coded := redis.LoadFromBase()

err := json.Unmarshal(coded, &p)

if (err != nil) {

    // handle error here

}


fmt.Println("Bytes:", coded)

fmt.Println("Unmarshalled:", p)


查看完整回答
反對 回復 2021-09-13
  • 1 回答
  • 0 關注
  • 173 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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