Unmarshal json in struct: cannot put array in Go value

I have a service that provides me properties through REST. Now I want to untie the body into a property structure. Please check out this example of a playground: click . When I have only one property, I can easily untie it in Property. However, ACTUAL's response from the server is somehow different. The actual answer I want to unleash is this:

[
    {
        "key": "blabla",
        "secret": false,
        "type": "string",
        "value": "hereisthevalue"
    },
    {
        "key": "yepyepakey",
        "secret": true,
        "type": "string",
        "value": "dummy"
    }
]

Unfortunately, I do not know how to do this. Can someone point me in the right direction?

+4
source share
1 answer

You need to unmount into a piece of property: http://play.golang.org/p/eRgjfBHypH

var props []Property
er := json.Unmarshal(resp, &props)
if er != nil {
    panic(er)
} else {
    fmt.Println(props)
}
+16
source

Source: https://habr.com/ru/post/1619513/


All Articles