My Go struct is like this:
type BaseModel struct {
Id string `json:"id"`
CreatedTime time.Time `json:"createdTime"`
UpdatedTime time.Time `json:"updatedTime"`
Deleted bool `json:"deleted"`
}
type Category struct {
BaseModel
Parent string `json:"parent"`
Name string `json:"name"`
IconClass string `json:"iconClass"`
Mark string `json:"mark"`
}
I want convert Category
to JSON like this:
{
"id":"",
"deleted":"",
...
"parent":"",
"name":""
}
But when I use Go's json to convert it, it gives me this:
{
"Id":"",
"Deleted":"",
...
"parent":"",
"name":"",
...
}
What should I do now?
I use under code to convert:
// define
var menus []models.Category
// query from db
q.Filter("deleted__exact", false).All(&menus)
// serialize it
res, _ := json.Marshal(&menus)
s := string(res[:])
beego.Debug(s)
</div>