Answer the question
In order to leave comments, you need to log in
How to properly convert json to struct?
The server receives a json string from the client:
{
"progectName": "fgrr",
"progectDesc": "rgd",
"progectType": [
"1",
"2"
],
"adrFullPath": "w3rw3r",
"adrInParam": "r3wr",
"adrOutParam": "fsefse",
"domains": [
{
"key": 1,
"value": "sefsef"
}
]
}
type ProgectData struct {
ProgectName string `json: "progectName"`
ProgectDesc string `json: "progectDesc"`
ProgectType []string `json: "progectType"`
AdrFullPath string `json: "adrFullPath"`
AdrInParam string `json: "adrInParam"`
AdrOutParam string `json: "adrOutParam"`
Domains DomainsData `json: "domains"`
}
type DomainsData struct {
Key int `json: "key"`
Value string `json: "value"`
}
func Dsd(d string) ProgectData {
text := []byte(d)
var s ProgectData
err := json.Unmarshal(text, &s)
if err != nil {
CheckErr(err)
}
return s
}
Domains []DomainsData `json: "domains"`
Answer the question
In order to leave comments, you need to log in
In your json domains, this is the DomainsData array. And in struct it is an instance of DomainsData
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question