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
What did you do?
I want to get the property of an object from neo4j and there is two properties with the same name but one is upper case and the other is lower case. And their type is different. The code is like
package main
import (
"myProject/config"
"myProject/log"
"myProject/service/neo4j"
)
type MetaData struct {
ID int64 json:"ID"
Name string json:"name"
}
func main() {
config.Init()
compID := int64(3)
preData := MetaData{}
err := neo4j.REST.GetNodeProperty(compID, &preData)
log.Info.Println("result is", preData.Name)
log.Info.Println("error is", err)
}
This is working as intended (documented).
Quote https://golang.org/pkg/encoding/json/#Unmarshal:
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.
When encoding/json finds the Name key, it finds that it
matches the field tag case-insensitively, and try to unmarshal
it into the field and get an error.
minux
changed the title
Unmarshal ignore the exact case and match the case-intensitive one and throw an error
encoding/json: Unmarshal ignore the exact case and match the case-intensitive one and throw an error
Apr 11, 2016
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
I want to get the property of an object from neo4j and there is two properties with the same name but one is upper case and the other is lower case. And their type is different. The code is like
The Get function called
func Unmarshal(data []byte, v interface{}) error
in https://golang.org/src/encoding/json/decode.go
neo4j data is like
{ id: 3, Name: [1,2,3], name: "test" }
which Name is an array and name is a string
it should get the lower case name property and ignore the upper case Name property
error is json: cannot unmarshal array into Go value of type string
The text was updated successfully, but these errors were encountered: