Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why json.Unmarshal method convert number value (in json string) to float value (in golang)? #27082

Closed
mthhk opened this issue Aug 19, 2018 · 3 comments

Comments

@mthhk
Copy link

mthhk commented Aug 19, 2018

BIAGT

@mvdan
Copy link
Member

mvdan commented Aug 19, 2018

Please read the documentation carefully: https://golang.org/pkg/encoding/json/#Unmarshal

To unmarshal JSON into an interface value, Unmarshal stores one of these in the interface value:
[...]
float64, for JSON numbers

@mvdan mvdan closed this as completed Aug 19, 2018
@mthhk
Copy link
Author

mthhk commented Aug 20, 2018

of cause i read it。
i mean,if go stories number value to float,the precision will be lost;
for an example ,how to Unmarshal {"key":123123123123123123123123"} ???

m := make(map[string]interface{})
originJson := {"key":1123123123123123123}
json.Unmarshal([]byte(originJson), &m)
fmt.Printf("origin json %s -> after parsed %v", originJson, m["key"])
===output====
origin json {"key":1123123123123123123} -> after parsed 1.1231231231231231e+181123123123123123123,--- PASS: TestInvocation412131 (0.00s)

@dominikh
Copy link
Member

Unlike many projects on GitHub, the Go project does not use its bug tracker for general discussion or asking questions. We only use our bug tracker for tracking bugs and tracking proposals going through the Proposal Process.

Please see https://golang.org/wiki/Questions for good places to ask questions.

@golang golang locked as off-topic and limited conversation to collaborators Aug 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants