[英]How to set an array in json response goLang-gin
I have an array of stucts stored a variable my array. 我有一个结构数组存储了我的数组变量。
Struct is 结构是
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"`
My array looks like this and is stored in a variable 'myArray'. 我的数组看起来像这样,并存储在变量“ myArray”中。 This array is formed by iterating over a set of rows coming from database.
该数组是通过迭代来自数据库的一组行而形成的。
[{1 abc default} {2 xyz default}]
I am using gin as http server. 我正在使用gin作为http服务器。 How do I set this array into JSON reponse using c.JSON.
如何使用c.JSON将此数组设置为JSON响应。 Something like
就像是
[
{
id: 1,
name : 'abc'
status: 'default'
},
{
id: 2,
name : 'xyz'
status: 'default'
}
]
ok c.JSON(http.StatusOK, myArray) worked. 好的c.JSON(http.StatusOK,myArray)工作了。 But I cannot see the Id field in the response.
但是我看不到响应中的Id字段。 Any reason why?
有什么原因吗? Is it because of 'int64' dataType?
是否因为“ int64”数据类型?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.