damren damren - 1 year ago 136
JSON Question

Golang JSON Unmarshal serialized number

I have a question about json.Unmarshal.
Playground example https://play.golang.org/p/3d0nUv7PSJ

The problem is: JSON does not unmarshal "1" to float. I mean "1" is a serialized JSON which should be a number. Am I doing something wrong ?:D

Answer Source

In JSON, "1" is a string. If you use 1 in your example instead, it's properly unmarshalled as a float.

Playground: https://play.golang.org/p/60symMsRSW

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download