jeudi 9 février 2017

Golang map json to struct

Vote count: 0

I have a JSON which I need to extract the data out of it using a struct:

I am trying to map it to the below struct:

type Message struct {
    Name   string `json:"name"`
    Values []struct {
        Value int `json:"value,omitempty"`
        Comments int `json:"comments,omitempty"`
        Likes    int `json:"likes,omitempty"`
        Shares   int `json:"shares,omitempty"`
    } `json:"values"`
}

but so far I am not able to read from it, I need to know how to structure my struct and how to read the name, values and comments, etc...

 [{
        "name": "organic_impressions_unique",
        "values": [{
            "value": 8288
        }]
    }, {
        "name": "post_story_actions_by_type",
        "values": [{
            "shares": 234,
            "comments": 838,
            "likes": 8768
        }]
    }]

asked 36 secs ago

Let's block ads! (Why?)



Golang map json to struct

Aucun commentaire:

Enregistrer un commentaire