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
I expect json.Unmarshal to work normally without error.
What did you see instead?
the program panic when either the field of EventTime or EventType of DepthItem struct is comment. panic: json: cannot unmarshal string into Go struct field DepthItem.data.E of type int
when both EventTime and EventType of DepthItem struct are comment, it work fine.
when both EventTime and EventType of DepthItem struct are uncomment, it works fine.
The error occurs because two fields has similary names "E" and "e".And, json.Unmarshal function can not distinguish them.
The text was updated successfully, but these errors were encountered:
You get the error because you commented out the `json:"E"` field, and the json package matches key names in a case insensitive way:
To unmarshal JSON into a struct, Unmarshal matches incoming object keys to the keys used by Marshal (either the struct field name or its tag), preferring an exact match but also accepting a case-insensitive match.
Also see #14750. The whole key name matching logic should be overhauled to be made less confusing, and we can't change this one behavior without breaking programs.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes , with go1.16.3 darwin/amd64
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The link is below
https://play.golang.org/p/7uoE9d7b1KM
What did you expect to see?
I expect json.Unmarshal to work normally without error.
What did you see instead?
the program panic when either the field of EventTime or EventType of DepthItem struct is comment.
panic: json: cannot unmarshal string into Go struct field DepthItem.data.E of type int
when both EventTime and EventType of DepthItem struct are comment, it work fine.
when both EventTime and EventType of DepthItem struct are uncomment, it works fine.
The error occurs because two fields has similary names "E" and "e".And, json.Unmarshal function can not distinguish them.
The text was updated successfully, but these errors were encountered: