Here's a simplified version what I'm trying to do:
type example struct {
Topics []struct {
Id int64 `json:"id"`
Title string `json:"title"`
Body string `json:"body"`
Tags []string `json:"tags"`
Search_phrases []string `json:"search_phrases"`
} `json:"topics"`
}
func main() {
body := []byte(
`
{
"topics": [{
"id": 35436,
"title": "How to Disassemble the ED209",
"body": "Carefully with very large pliers",
"tags": ["danger"],
"search_phrases": ["red", "yellow"]
}]
}
`)
var topics []example
err := json.Unmarshal(body, &topics)
if err != nil {
fmt.Println(err)
}
/*
for _, topics := range topics {
//doSomething
}
*/
}
This looks fine to me, but I am getting:
"json: cannot unmarshal object into Go value of type []main.example"
I'm probably just missing something small, but I can't seem to find it at the moment.