我正在做一項服務,向 Expo 后端發送推送通知。一旦 http 調用 Expo 以波紋管格式響應(根據 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 }]}這是一個提供的響應示例:{ "data": [ { "status": "error", "message": "\\\"ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]\\\" is not a registered push notification recipient", "details": { "error": "DeviceNotRegistered" } }, { "status": "ok", "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" } ]}我創建了結構來解碼響應。現在我嘗試解碼“詳細信息”字段的響應時出錯,無論我在我的結構中使用什么類型。我如何處理將 expo 標記為“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{}}這是我正在使用的結構。我也通過查看示例進行了嘗試: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"` }但每次都會收到類似“json:無法將對象解組到 Go struct 字段 DataPart.data.details”之類的錯誤
- 1 回答
- 0 關注
- 90 瀏覽
添加回答
舉報
0/150
提交
取消