1
0
mirror of https://github.com/json-iterator/go.git synced 2025-05-16 21:45:43 +02:00

Merge pull request #49 from zhaitianduo/master

Use jsoniter instead of json in example
This commit is contained in:
Tao Wen 2017-06-09 03:32:31 -05:00 committed by GitHub
commit 4f909776cf

View File

@ -2,9 +2,9 @@ package jsoniter_test
import ( import (
"fmt" "fmt"
"github.com/json-iterator/go"
"os" "os"
"encoding/json"
"github.com/json-iterator/go"
) )
func ExampleMarshal() { func ExampleMarshal() {
@ -33,15 +33,15 @@ func ExampleUnmarshal() {
{"Name": "Quoll", "Order": "Dasyuromorphia"} {"Name": "Quoll", "Order": "Dasyuromorphia"}
]`) ]`)
type Animal struct { type Animal struct {
Name string Name string
Order string Order string
} }
var animals []Animal var animals []Animal
err := json.Unmarshal(jsonBlob, &animals) err := jsoniter.Unmarshal(jsonBlob, &animals)
if err != nil { if err != nil {
fmt.Println("error:", err) fmt.Println("error:", err)
} }
fmt.Printf("%+v", animals) fmt.Printf("%+v", animals)
// Output: // Output:
// [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}] // [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}]
} }