jsoniter_demo_test.go 441 B

123456789101112131415161718192021222324
  1. package jsoniter
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/json-iterator/go/require"
  6. )
  7. func Test_bind_api_demo(t *testing.T) {
  8. should := require.New(t)
  9. val := []int{}
  10. err := UnmarshalFromString(`[0,1,2,3] `, &val)
  11. should.Nil(err)
  12. should.Equal([]int{0, 1, 2, 3}, val)
  13. }
  14. func Test_iterator_api_demo(t *testing.T) {
  15. iter := ParseString(`[0,1,2,3]`)
  16. total := 0
  17. for iter.ReadArray() {
  18. total += iter.ReadInt()
  19. }
  20. fmt.Println(total)
  21. }