I got following struct:
type Data struct {
Data1 int
Data2 int
ImpData []struct {
Title string
ID string
TextS string
}
}
I unmarshall the jsoncode into var o
var o Data
err = json.Unmarshal(output, &o)
if err != nil {
panic(err.Error())
}
I get the data with a for loop (for testing output)
for i := 0; i < len(o.ImpData); i++ {
fmt.Printf(" Test: %+v", o.ImpData[i].Title)
}
Till this point everything works, but i dont know how to excatly execute the Template with the right parameters and data.
tmpl, _ := template.ParseFiles("index.html")
tmpl.Execute(w, o)
HTML:
<p style="color: black;"> {{ range .o }} {{ . }} {{end}}</p>
This doesnt work and i tried everyhting.
New contributor
Thomas Wilscheid is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.