| 12345678910111213141516171819202122232425262728 |
- package jsoniter_test
- import (
- "fmt"
- "github.com/json-iterator/go"
- "os"
- "testing"
- )
- func Test_ExampleMarshal(t *testing.T) {
- 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"]}
- }
|