1
0
mirror of https://github.com/json-iterator/go.git synced 2025-05-28 22:17:38 +02:00

use jsoniter for example

This commit is contained in:
zhaitianduo 2017-06-09 16:25:58 +08:00
parent 2608d40f2a
commit 46d443fbad

@ -1,10 +1,10 @@
package jsoniter_test package jsoniter_test
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/json-iterator/go" "github.com/json-iterator/go"
"os" "os"
"encoding/json"
) )
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}]
} }