UnMarshal will do its best to accommodate the data that best aligns with your structure. Technically, your first example will work, but you are trying to access the Value field with dotted notation, even if you stated that it is a map:
This should give you some form of output:
if data.Type == 'image'{ fmt.Printf("%v\n", data.Value["Imagedata"]) }
... given that "Imagedata" is the key to json.
You have the option to define the structure as deep as you want, or expect the structure to be, or use the {} interface, and then make type statements for the values. When the Value field is a map, you will always access keys such as Value[key] , and then the value of this map is the {} interface, which you can enter assert, for example Value[key].(float64)
Regarding the implementation of more explicit structures, I found that you can either split the objects into your own structures, or define it nested in one place:
Nested (with anonymous structure)
type Frame struct { Type string Value struct { Imagedata string `json:"image_data"` } }
Separate structures
type Frame struct { Type string Value value } type value struct { Imagedata string `json:"image_data"` }
I am still participating. Go it yourself, so this is my understanding :-)
jdi Mar 21 '12 at 9:05 2012-03-21 09:05
source share