我正在做一项服务,向 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 关注
- 124 浏览
添加回答
举报
0/150
提交
取消
