Slide 33
Slide 33 text
type Device struct {
Type string `json:"type"`
SN *string `json:"sn,omitempty"` // pointer!
GatewaySN *string `json:"gateway_sn,omitempty"` // pointer!
Channel *uint `json:"channel,omitempty"` // pointer!
}
input := `{"type": "Gateway", "sn": "3FCF54AADCB6E7DC"}`
device := Device{}
json.Unmarshal([]byte(input), &device)
fmt.Println(device) // {Gateway 0x1050c160 }
output, _ := json.Marshal(device)
fmt.Printf("%s\n", output) // {"type":"Gateway","sn":"3FCF54AADCB6E7DC"}