1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-04 21:34:16 +02:00
json-iterator/jsoniter_demo_test.go

25 lines
441 B
Go
Raw Normal View History

2016-12-11 15:53:35 +08:00
package jsoniter
import (
"fmt"
"testing"
2017-05-05 17:44:09 +08:00
"github.com/json-iterator/go/require"
2016-12-11 15:53:35 +08:00
)
func Test_bind_api_demo(t *testing.T) {
2017-05-05 17:44:09 +08:00
should := require.New(t)
2016-12-11 15:53:35 +08:00
val := []int{}
2017-05-05 17:44:09 +08:00
err := UnmarshalFromString(`[0,1,2,3] `, &val)
should.Nil(err)
should.Equal([]int{0, 1, 2, 3}, val)
2016-12-11 15:53:35 +08:00
}
func Test_iterator_api_demo(t *testing.T) {
iter := ParseString(`[0,1,2,3]`)
total := 0
for iter.ReadArray() {
total += iter.ReadInt()
}
fmt.Println(total)
2017-06-02 16:52:20 +08:00
}