I want to unmarshal the followng json in golang. I am not able to access the inner data . What is the best way to do it?
{
"1": {
"enabled": 1,
"pct": 0.5
},
"2": {
"enabled": 1,
"pct": 0.6
},
"3": {
"enabled": 1,
"pct": 0.2
},
"4": {
"enabled": 1,
"pct": 0.1
}
}
I use
type regs struct {
enabled bool `json:"enabled,omitempty"`
pct float64 `json:"pct,omitempty"`
}
var r map[string]regs
if err := json.Unmarshal([]byte(jStr), &r); err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", r)
but i dont see the values inside the struct.
Result: map[1:{enabled:false pct:0} 2:{enabled:false pct:0} 3:{enabled:false pct:0} 4:{enabled:false pct:0}]