golang结构体序列化
golang中最常用的功能之一,序列化和反序列化,golang自带的方法:
import "encoding/json"
// 序列化
func Marshal(v interface{}) ([]byte, error)
// 反序列化
func Unmarshal(data []byte, v interface{}) error
忽略字段
type BeanDemo struct {
Name string `json:"-"`
}
忽略空值字段
type BeanDemo struct {
Name string `json:"name,omitempty"`
}