1
0
mirror of https://github.com/json-iterator/go.git synced 2025-03-29 21:20:52 +02:00
json-iterator/example_test.go

28 lines
479 B
Go
Raw Normal View History

2017-06-05 20:37:08 +08:00
package jsoniter_test
import (
"fmt"
"github.com/json-iterator/go"
"os"
)
2017-06-05 22:10:01 +08:00
func ExampleMarshal() {
2017-06-05 20:37:08 +08:00
type ColorGroup struct {
ID int
Name string
Colors []string
}
group := ColorGroup{
ID: 1,
Name: "Reds",
Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
}
b, err := jsoniter.Marshal(group)
if err != nil {
fmt.Println("error:", err)
}
os.Stdout.Write(b)
// Output:
// {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}
}