Golang JSON解码在数组上失败

I have an object like:

   a = [{
        "name": "rdj",
        "place": "meh",
        "meh" : ["bow", "blah"]
    }]

I defined a struct like:

type first struct {
    A []one
}

type one struct {
    Place string `json: "place"`
    Name string `json: "name"`
}

when I use the same in code like:

func main() {
    res, _ := http.Get("http://127.0.0.1:8080/sample/")
    defer res.Body.Close()
    var some first
    rd := json.NewDecoder(res.Body)
    err := rd.Decode(&some)
    errorme(err)
    fmt.Printf("%+v
", some)
}

I get the below error:

panic: json: cannot unmarshal array into Go value of type main.first

My understanding is:

type first defines the array and within that array is data structure defined in type one.

The JSON is an array of objects. Use these types:

type one struct {   // Use struct for JSON object
  Place string `json: "place"`
  Name string `json: "name"`
}

...

var some []one   // Use slice for JSON array
rd := json.NewDecoder(res.Body)
err := rd.Decode(&some)

The the types in the question match this JSON structure:

{"A": [{
    "name": "rdj",
    "place": "meh",
    "meh" : ["bow", "blah"]
}]}

@rickydj,

  1. If you need to have "first" as a separate type: type first []one

  2. If you do not care about having "first" as a separate type, just cut down to var some []one as @Mellow Marmot suggested above.