```go
package main
import (
"encoding/json"
"fmt"
"github.com/satori/go.uuid"
)
func main() {
u,_ := uuid.NewV4()
s := struct {
Id string `json:"id"`
Name string `json:"name"`
Age uint `json:"age"`
Sex bool `json:"sex"`
Address string `json:"address"`
}{u.String(),"xmge",26,true,"西二旗上地科技大厦"}
resp1, _ := json.Marshal(s)
resp2, _ := json.MarshalIndent(s, "", " ")
fmt.Println("resp1:\n",string(resp1))
fmt.Println("resp2:\n",string(resp2))
}
// result
resp1:
{"id":"5f5001e9-3b89-401f-89bf-0931cb0afdec","name":"xmge","age":26,"sex":true,"address":"西二旗上地科技大厦"}
resp2:
{
"id": "5f5001e9-3b89-401f-89bf-0931cb0afdec",
"name": "xmge",
"age": 26,
"sex": true,
"address": "西二旗上地科技大厦"
}
```
有疑问加站长微信联系(非本文作者)