dynamic-struct
dynamic-struct copied to clipboard
Can we assign a structure variable to a structure field
instance := dynamicstruct.NewStruct(). AddField("Integer", 0, json:"int"). AddField("Text", "", json:"someText"). AddField("Float", 0.0, json:"double"). AddField("Boolean", false, ""). AddField("Slice", []interface{}{}, ""). AddField("Anonymous", "", json:"-"`).
Build().
New()
data := []byte(`
{
"int": 123,
"someText": "example",
"double": 123.45,
"Boolean": true,
"Slice": {
"Test": 124,
"Test2": 234
},
"Anonymous": "avoid to read"
}
)
The error message is as follows:
json: cannot unmarshal object into Go struct field .Slice of type []interface {}
exit status 1