我想绑定一个 json 对象数组,如下所示:
[
{
"id": "someid"
},
{
"id": "anotherid"
}
]
Run Code Online (Sandbox Code Playgroud)
这是我的模型
type DeleteByID struct {
ID string `json:"id" binding:"required"`
}
Run Code Online (Sandbox Code Playgroud)
我使用 gin 来处理该对象
var stock []DeleteByID
if err := ctx.ShouldBindJSON(&stock); err != nil {
return err
}
Run Code Online (Sandbox Code Playgroud)
问题是它没有绑定/检查我的对象。