Come eseguire il marshalling di una struttura nidificata in JSON? So come eseguire il marshalling della struct senza alcuna struttura annidata. Tuttavia quando provo a rendere la risposta JSON simile a questa:Strutture nidificate di marshall in JSON
{"genre": {"country": "taylor swift", "rock": "aimee"}}
Mi imbatto in problemi.
Il mio codice è simile al seguente:
Go:
type Music struct {
Genre struct {
Country string
Rock string
}
}
resp := Music{
Genre: { // error on this line.
Country: "Taylor Swift",
Rock: "Aimee",
},
}
js, _ := json.Marshal(resp)
w.Write(js)
Tuttavia, ottengo l'errore
Missing type in composite literal
Come risolvo questo?
grazie! il primo esempio non ha funzionato anche se – user3918985