给定一个结构
type Company struct {
ID int `json:"id"`
Abn sql.NullString `json:"abn,string"`
}
当用这样的东西编组时
company := &Company{}
company.ID = 68
company.Abn = "SomeABN"
result, err := json.Marshal(company)
结果是
{
"id": "68",
"abn": {
"String": "SomeABN",
"Valid": true
}
}
想要的结果是
{
"id": "68",
"abn": "SomeABN"
}
我试过明确说明 Abn 是一个字符串。
Abn sql.NullString `json:"abn,string"`
这并没有改变结果。
您如何编组 sql.NullString 以便将输出展平以仅提供 go 中的值?
qq_笑_17
偶然的你
哆啦的时光机
慕斯709654
相关分类