mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-11-02 21:14:07 +08:00
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:
24
jsonUtil/json_to_struct_slice_test.go
Normal file
24
jsonUtil/json_to_struct_slice_test.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user