example_test.go 507 B

12345678910111213141516171819202122232425262728
  1. package jsoniter_test
  2. import (
  3. "fmt"
  4. "github.com/json-iterator/go"
  5. "os"
  6. "testing"
  7. )
  8. func Test_ExampleMarshal(t *testing.T) {
  9. type ColorGroup struct {
  10. ID int
  11. Name string
  12. Colors []string
  13. }
  14. group := ColorGroup{
  15. ID: 1,
  16. Name: "Reds",
  17. Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
  18. }
  19. b, err := jsoniter.Marshal(group)
  20. if err != nil {
  21. fmt.Println("error:", err)
  22. }
  23. os.Stdout.Write(b)
  24. // Output:
  25. // {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}
  26. }