2 回答

TA贡献1829条经验 获得超7个赞
您可以直接解组为数组
data := `[
{
"ProfileID": 1,
"Title": "65micron"
},
{
"ProfileID": 2,
"Title": "80micron"
}]`
type Profile struct {
ProfileID int
Title string
}
var profiles []Profile
json.Unmarshal([]byte(data), &profiles)
您也可以直接从Request.Body.
func Handler(w http.ResponseWriter, r *http.Request) {
var profiles []Profile
json.NewDecoder(r.Body).Decode(&profiles)
// use `profiles`
}

TA贡献1784条经验 获得超9个赞
你应该定义一个结构
type Profile struct {
ID int `json:"ProfileID"`
Title string `json:"Title"`
}
在解码响应之后
var r []Profile
err := json.NewDecoder(res.Body).Decode(&r)
- 2 回答
- 0 关注
- 153 浏览
添加回答
举报