我有一个结构数组,我的数组中存储了一个变量。结构是 type myStruct struct { id int64 `db:"id" json:"id"` Name string `form:"name" db:"name" json:"name" binding:"required"` Status string `form:"status" db:"status" json:"status" binding:"required"`我的数组看起来像这样,并存储在变量“myArray”中。该数组是通过迭代来自数据库的一组行而形成的。[{1 abc default} {2 xyz default}]我使用 gin 作为 http 服务器。如何使用 c.JSON 将此数组设置为 JSON 响应。就像是[ { id: 1, name : 'abc' status: 'default' }, { id: 2, name : 'xyz' status: 'default' }]
1 回答

千巷猫影
TA贡献1829条经验 获得超7个赞
好的 c.JSON(http.StatusOK, myArray) 工作。但我在响应中看不到 Id 字段。有什么理由吗?是因为“int64”数据类型吗?
- 1 回答
- 0 关注
- 201 浏览
添加回答
举报
0/150
提交
取消