Assume i have a struct like
type A struct{
name string`json:\"name\"`
}
Then in main i have code
var jsonString string =
To add to icza's answer, you can also get an error if you try to Unmarshal into a typed nil pointer. This can happen if, for example, you make a slice of pointers to a particular type, then try and unmarshal into a particular one of those pointers.
package main
import (
"fmt"
"encoding/json"
)
type Example struct {Name string}
func main() {
exs := make([]*Example, 5)
err := json.Unmarshal([]byte(`{"name":"jane"}`), exs[0])
fmt.Println(err)
}
// json: Unmarshal(nil *main.Example)