You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is about the json package, concretely the Unmarshal function.
My version of go: 1.10.2 windows/amd and the go env is not relevant because it happens too on play.golang.org (see the link with the example here: https://play.golang.org/p/NGoR7Vs-VxX ).
The problem I am finding is that I am receiving a json that includes an array like this:
My question is... why should value field be a interface type?? I mean... every number can be converted to string without any problem... so, why can´t I use string as type and the json decoder makes responsible to realize the conversion (if it is necessary)??
I have been diving a little on the code of the decode file, and... in this line:
removing the second condition of the if (&& v.Type() == numberType) works for me. I guess it is a security statement or maybe something important that I don´t understand. But... when does v.Type() will be different than v.Kind()?? or... when does the v.Kind() will be a string and the v.Type() a json.Number??
Thanks in advance.
PS: Finally I found this solution using UnmarshalJSON function: https://play.golang.org/p/egqc6KJK1-t but I would want to know the reason of the non-autoconversion.
The text was updated successfully, but these errors were encountered:
meirf
changed the title
Json Unmarshal. Expected type string -> found int.
encoding/json: Unmarshal. Expected type string -> found int.
Aug 11, 2018
This appears to be a question rather than a Go bug. We do not use the issue tracker for general discussions or questions like these. The Github bug tracker is only used for tracking bugs and proposals going through the Proposal Process.
Please feel free to reach out to the forums in the Questions wiki page; it has a list of good places for asking questions.
Hi everyone.
This issue is about the json package, concretely the Unmarshal function.
My version of go: 1.10.2 windows/amd and the go env is not relevant because it happens too on play.golang.org (see the link with the example here: https://play.golang.org/p/NGoR7Vs-VxX ).
The problem I am finding is that I am receiving a json that includes an array like this:
My question is... why should
value
field be a interface type?? I mean... every number can be converted to string without any problem... so, why can´t I use string as type and the json decoder makes responsible to realize the conversion (if it is necessary)??I have been diving a little on the code of the decode file, and... in this line:
go/src/encoding/json/decode.go
Line 984 in 5c11480
removing the second condition of the if (
&& v.Type() == numberType
) works for me. I guess it is a security statement or maybe something important that I don´t understand. But... when does v.Type() will be different than v.Kind()?? or... when does the v.Kind() will be a string and the v.Type() a json.Number??Thanks in advance.
PS: Finally I found this solution using
UnmarshalJSON
function: https://play.golang.org/p/egqc6KJK1-t but I would want to know the reason of the non-autoconversion.The text was updated successfully, but these errors were encountered: