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 關注
- 131 瀏覽
添加回答
舉報