package main
import (
"encoding/json"
"fmt"
)
type IT struct { //一定要注意这里的成员变量的名字首字母必须是大写
Company string
Subjects []string
Isok bool
Price float64
}
func main() {
s := IT{"zyg", []string{"go", "python", "java"}, true, 3.14}
buf, err := json.Marshal(s)
if err != nil {
fmt.Println("err = ", err)
return
}
fmt.Println("buf = ", string(buf))
buf, err = json.MarshalIndent(s, "", " ") // 将json形式的字符串进行格式化
fmt.Println(string(buf))
}