There are several issues in your code.
-
First of all, all the fields of your
edit
struct must be exported which means you should capitalize the first letter of every fields.
Just like the following:type edit struct { Id Values }
-
The data type of of
key
of theValues
field must be string to be able to decode thejson
data.type edit struct { Id int Values map[string]interface{} }
-
Finally, data type of your
json
data"id"
is wrong. It must beint
to be matched to yourGo
struct. Also, there is no"m"
defined in your struct. The"m"
must be replaced with"values"
to match yourGo
struct. Just like the following{ "id": 5, "values":{ "name": "alice" } }
Just to let you know, you can simply use following piece of code to unmarshal json
data into Go
struct.
err := json.Unmarshal([]byte(a), &s)
1
solved How to decode embedded json? [closed]