1
2
3
4
5
6
7
8
9
10
11
12
13
| type Test struct {
Total int `json:"total"`
item string `json:"item"`
}
func main() {
resp := Test{
Total: 1,
item: "aa",
}
body, err := json.Marshal(resp)
fmt.Printf("body=%v, err=%v \n", string(body), err) // 输出 body={"total":1}, err=<nil>
}
|