My input JSON, has a list of different elements.
I have problems with the number of the first element of response.
package main
import (
"fmt"
"log"
"encoding/json"
)
var j = ` {
"response": [
777, // problem here !!!
{
"id": 888,
"from_id": 999,
"to_id": 888,
"text": "hello..."
},
{
"id": 999,
"from_id": 888,
"to_id": 999,
"text": "goodbye..."
}
]
}`
type D struct {
Id int `json:"id"`
FromId int `json:"from_id"`
ToId int `json:"to_id"`
Text string `json:"text"`
}
type R struct {
Count int
Response []D `json:"response"`
}
func main() {
var data = new(R)
err := json.Unmarshal([]byte(j), &data)
if err != nil {
log.Fatal(err)
}
fmt.Println(data.Response)
}
Error on output. I do not understand where the error. Help me please.