mirror of
https://github.com/json-iterator/go.git
synced 2025-01-20 18:48:32 +02:00
example test
This commit is contained in:
parent
404c0ee44b
commit
c0a4ad72e1
27
example_test.go
Normal file
27
example_test.go
Normal file
@ -0,0 +1,27 @@
|
||||
package jsoniter_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/json-iterator/go"
|
||||
"os"
|
||||
)
|
||||
|
||||
func ExampleMarshal() {
|
||||
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"]}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user