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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Go Struct解碼博覽會(huì)推送通知響應(yīng)?

Go Struct解碼博覽會(huì)推送通知響應(yīng)?

Go
精慕HU 2022-11-23 19:59:14
我正在做一項(xiàng)服務(wù),向 Expo 后端發(fā)送推送通知。一旦 http 調(diào)用 Expo 以波紋管格式響應(yīng)(根據(jù) Expo):{  "data": [    {      "status": "error" | "ok",      "id": string, // this is the Receipt ID      // if status === "error"      "message": string,      "details": JSON    },    ...  ],  // only populated if there was an error with the entire request  "errors": [{    "code": number,    "message": string  }]}這是一個(gè)提供的響應(yīng)示例:{  "data": [    {      "status": "error",      "message": "\\\"ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]\\\" is not a registered push notification recipient",      "details": {        "error": "DeviceNotRegistered"      }    },    {      "status": "ok",      "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"    }  ]}我創(chuàng)建了結(jié)構(gòu)來解碼響應(yīng)?,F(xiàn)在我嘗試解碼“詳細(xì)信息”字段的響應(yīng)時(shí)出錯(cuò),無論我在我的結(jié)構(gòu)中使用什么類型。我如何處理將 expo 標(biāo)記為“JSON”的字段?import (    uuid "github.com/satori/go.uuid")type PushResult struct {    Errors []ErrorDetails `json:"errors,omitempty"`    Datas   []DataPart     `json:"data,omitempty"`}type ErrorDetails struct {    Code    int32  `json:"code,omitempty"`    Message string `json:"message,omitempty"`}type DataPart struct {    Status  string    `json:"status,omitempty"`    ID      uuid.UUID `json:"id,omitempty"`    Message string    `json:"message,omitempty"`    Details string `json:"details,omitempty"` //also tried map[string]string and interface{}}這是我正在使用的結(jié)構(gòu)。我也通過查看示例進(jìn)行了嘗試:type DataPart struct {    Status  string    `json:"status,omitempty"`    ID      uuid.UUID `json:"id,omitempty"`    Message string    `json:"message,omitempty"`    Details struct{           Error string `json:"error"`} `json:"details,omitempty"` }但每次都會(huì)收到類似“json:無法將對(duì)象解組到 Go struct 字段 DataPart.data.details”之類的錯(cuò)誤
查看完整描述

1 回答

?
繁華開滿天機(jī)

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超4個(gè)贊

我剛剛使用您的響應(yīng)示例創(chuàng)建了您的結(jié)構(gòu),它工作得很好。

操場(chǎng)

也就是說,如果您想要一種更好的調(diào)試“解組錯(cuò)誤”的方法,您可以解包它。這樣您就可以打印其他數(shù)據(jù)。

var t *json.UnmarshalTypeError
if errors.As(err, &t) {
    spew.Dump(t)
}

示例-> 我將錯(cuò)誤類型更改為整數(shù),這樣我就可以偽造錯(cuò)誤。

OBS:請(qǐng)注意,您的“數(shù)據(jù)”是一個(gè)數(shù)組,只有第一個(gè)有錯(cuò)誤。


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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