看一下encoding /
json.Marshal的文档。它讨论了如何使用struct字段标签来确定如何格式化生成的json。
例如:
type T struct { FieldA int `json:"field_a"` FieldB string `json:"field_b,omitempty"`}这将生成JSON,如下所示:
{ "field_a": 1234, "field_b": "foobar"}
看一下encoding /
json.Marshal的文档。它讨论了如何使用struct字段标签来确定如何格式化生成的json。
例如:
type T struct { FieldA int `json:"field_a"` FieldB string `json:"field_b,omitempty"`}这将生成JSON,如下所示:
{ "field_a": 1234, "field_b": "foobar"}