diff --git a/data_types.go b/data_types.go index 12820f4..7a81be4 100644 --- a/data_types.go +++ b/data_types.go @@ -38,6 +38,35 @@ func (id *ID) UnmarshalJSON(data []byte) error { return json.Unmarshal(data, (*string)(id)) } +type IntPairs [][]int + +func (p *IntPairs) UnmarshalJSON(data []byte) error { + var raw [][]json.Number + if err := json.Unmarshal(data, &raw); err != nil { + return err + } + if raw == nil { + *p = nil + return nil + } + out := make(IntPairs, len(raw)) + for i, pair := range raw { + out[i] = make([]int, len(pair)) + for j, n := range pair { + if n == "" { + continue + } + v, err := n.Int64() + if err != nil { + return err + } + out[i][j] = int(v) + } + } + *p = out + return nil +} + // Timestamp is the number of seconds since the UNIX epoch type Timestamp uint64 diff --git a/json.go b/json.go index 9ae5140..87a494a 100755 --- a/json.go +++ b/json.go @@ -244,7 +244,7 @@ type Attachment struct { Latitude string `json:"lat,omitempty"` Longitude string `json:"lng,omitempty"` Placeholder string `json:"placeholder,omitempty"` - Charmap [][]int `json:"charmap,omitempty"` + Charmap IntPairs `json:"charmap,omitempty"` ReplyID ID `json:"reply_id,omitempty"` BaseReplyID ID `json:"base_reply_id,omitempty"` UserID ID `json:"user_id,omitempty"`