1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-06 22:36:25 +02:00
This commit is contained in:
Tao Wen 2017-06-09 17:06:38 +08:00
commit 6bd13c2948

View File

@ -2,8 +2,9 @@ package jsoniter_test
import ( import (
"fmt" "fmt"
"github.com/json-iterator/go"
"os" "os"
"github.com/json-iterator/go"
) )
func ExampleMarshal() { func ExampleMarshal() {
@ -25,3 +26,22 @@ func ExampleMarshal() {
// Output: // Output:
// {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]} // {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}
} }
func ExampleUnmarshal() {
var jsonBlob = []byte(`[
{"Name": "Platypus", "Order": "Monotremata"},
{"Name": "Quoll", "Order": "Dasyuromorphia"}
]`)
type Animal struct {
Name string
Order string
}
var animals []Animal
err := jsoniter.Unmarshal(jsonBlob, &animals)
if err != nil {
fmt.Println("error:", err)
}
fmt.Printf("%+v", animals)
// Output:
// [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}]
}