- Joined
- Aug 17, 2018
(Un)marshaling JSON in GoLang is the most cancerous thing ever. This is what you have to do to unmarshal a simple array.
Code:err = json.Unmarshal(message, &[]interface{}{&trade.ChannelID, &trade.Type, &[]interface{}{&trade.Trade.MTS, &trade.Trade.ID, &trade.Trade.Amount, &trade.Trade.Price}})
I find static typed JSON decoding to be comfy:
Code:
type StationItem struct {
Value string
Type string
TypeStr string
Weight string
}
type ConnectionItem struct {
Date uint64
Start StationItem
Link string
Price *float32
Destination StationItem
StartTime uint64
DestinationTime uint64
}
var v []ConnectionItem
if err := json.Unmarshal(msg, &v); err != nil {
log.Fatal(err)
}