运行
格式化
停止
分享
赞助
package main import ( "encoding/json" //"fmt" "os" ) type Invoice struct { Title string `json:"title"` } func main() { fileType := "json" fileVersion := 1 invoices := []*Invoice{ &Invoice{ Title: "Invoice 1", }, &Invoice{ Title: "Invoice 2", }, } encoder := json.NewEncoder(os.Stdout) encoder.Encode(fileType) encoder.Encode(fileVersion) encoder.Encode(invoices) // Output: //"json" //1 //[{"title":"Invoice 1"},{"title":"Invoice 2"}] }