mirror of
https://github.com/json-iterator/go.git
synced 2024-11-24 08:22:14 +02:00
Merge branch 'master' of https://github.com/json-iterator/go
This commit is contained in:
commit
6bd13c2948
@ -2,8 +2,9 @@ package jsoniter_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/json-iterator/go"
|
||||
"os"
|
||||
|
||||
"github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func ExampleMarshal() {
|
||||
@ -25,3 +26,22 @@ func ExampleMarshal() {
|
||||
// Output:
|
||||
// {"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}]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user