Golang JSON Unmarshal 序列化数字

huangapple go评论127阅读模式
英文:

Golang JSON Unmarshal serialized number

问题

我对json.Unmarshal有一个问题。
Playground示例https://play.golang.org/p/3d0nUv7PSJ

问题是:JSON无法将"1"解组为浮点数。我的意思是"1"是一个序列化的JSON,应该是一个数字。我做错了什么吗?:D

英文:

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

答案1

得分: 2

在JSON中,"1"是一个字符串。如果你在你的示例中使用1,它将被正确解析为浮点数。

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

英文:

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

huangapple
  • 本文由 发表于 2016年8月22日 03:46:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/39068253.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定