go icon indicating copy to clipboard operation
go copied to clipboard

unmarshal from 2d array string to 1d array will return no error

Open horsdy opened this issue 2 years ago • 0 comments

OS: window 10 go version: go1.19 windows/amd64 json-iterator: v1.1.12 purpose:unmarshal from 2d array string to 1d array and error will return

type Person struct {
	Age  int64  `json:"age"`
	Name string `json:"name"`
}

func TestAnything3(t *testing.T) {
	var s = `[
		[
			{
				"age": 1,
				"name": "jack"
			}
		]
	]`
	var ps []*Person
	err := jsoniter.Unmarshal([]byte(s), &ps)
	fmt.Printf("ps: len:%v\n", len(ps))
	fmt.Printf("ps: value:\n")
	for k, v := range ps {
		fmt.Printf("k:%v, v:%v\n", k, v)
	}
	fmt.Printf("err: %v\n", err)
}

result: === RUN TestAnything3 ps: len:1 ps: value: k:0, v:&{0 } err: nil --- PASS: TestAnything3 (0.00s) PASS

err should not be nil

horsdy avatar Mar 03 '23 04:03 horsdy