fix:parse slices (#37)

1. Does not support parsing map type
2. Parse the slice type, if the data type is inconsistent, panic error

close #35
This commit is contained in:
jeffery
2023-05-11 17:41:34 +08:00
committed by GitHub
parent 7775125621
commit bbe169cba0
11 changed files with 692 additions and 32 deletions

View File

@@ -0,0 +1,24 @@
package jsonUtil
import (
"testing"
)
func TestJsonToStructSlice1(t *testing.T) {
data := `
{
"uid": 43015653,
"fids": ["43015653", 43015666]
}
`
var target struct {
Uid int `json:"uid"`
Fids []string `json:"fids"`
}
err := JsonToStruct(data, &target)
if err != nil {
t.Errorf("err %s", err)
return
}
}