gpt4 book ai didi

go - 如何从 json 中删除字段?

转载 作者:IT王子 更新时间:2023-10-29 01:59:45 28 4
gpt4 key购买 nike

我的代码中有这个结构。

type AppVersion struct {
Id int64 `json:"id"`
App App `json:"app,omitempty" out:"false"`
AppId int64 `sql:"not null" json:"app_id"`
Version string `sql:"not null" json:"version"`
Sessions []Session `json:"-"`
SessionsCount int `sql:"-"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt time.Time `json:"deleted_at"`
}

我正在构建一个网络服务,我不需要在 JSON 中发送 App 字段。我已经尝试了一些方法来从 JSON 中删除该字段,但我无法做到。

我怎样才能做到这一点?有没有办法将结构设置为空?

我使用 GORM 作为数据库访问层,所以我不确定我是否可以做 App *App,你知道它是否可行吗?

最佳答案

type AppVersion struct {
Id int64 `json:"id"`
App App `json:"-"`
AppId int64 `sql:"not null" json:"app_id"`
Version string `sql:"not null" json:"version"`
Sessions []Session `json:"-"`
SessionsCount int `sql:"-"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt time.Time `json:"deleted_at"`
}

更多信息 - json-go

关于go - 如何从 json 中删除字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26548732/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com