郑州软件app开发公司,嘉兴优化网站排名,用阿里巴巴店铺做公司网站怎么样,企业营销型企业网站建设json标签 json:- // 表示不进行序列化,忽略 json:name,omitempty//加上omitempty#xff0c;可以在序列化的时候忽略0值或者空值#xff1b;若要在被嵌套结构体整体为空时使其在序列化结果中被忽略#xff0c;不仅要在被嵌套结构体字段后加json:“…json标签 json:- // 表示不进行序列化,忽略 json:name,omitempty//加上omitempty可以在序列化的时候忽略0值或者空值若要在被嵌套结构体整体为空时使其在序列化结果中被忽略不仅要在被嵌套结构体字段后加json:“name,omitempty”还要将其改为结构体指针 json:,inline通常作用于内嵌的结构体类型type package mainimport (encoding/jsonfmt
)
type T1 struct {FieldInt int json:field_intFieldIgnore int json:- //忽略FieldBooleab bool json:field_boolean,string //不同类型FieldString1 string json:field_string1,omitempty //忽略空值当时复合结构时为要为指针类型FieldString2 string json:field_string2,omitempty
}
type T2 struct {T1 json:,inline //表示内嵌与T1输出一致
}func main() {val1 : T1{FieldInt: 11,FieldIgnore: 11,FieldBooleab: true,FieldString2: no empty,}bty1, _ : json.Marshal(val1)fmt.Printf(%v\r\n, string(bty1))val2 : T2{val1,}bty2, _ : json.Marshal(val2)fmt.Printf(%v\r\n, string(bty2))
}// output
// {field_int:11,field_boolean:true,field_string2:no empty}
// {field_int:11,field_boolean:true,field_string2:no empty}