This commit is contained in:
John Guo
2022-04-18 20:57:41 +08:00
parent be77779aff
commit d260de15ba
2 changed files with 10 additions and 2 deletions

View File

@ -264,14 +264,18 @@ func checkJsonAndUnmarshalUseNumber(any interface{}, target interface{}) bool {
switch r := any.(type) {
case []byte:
if json.Valid(r) {
_ = json.UnmarshalUseNumber(r, &target)
if err := json.UnmarshalUseNumber(r, &target); err != nil {
return false
}
return true
}
case string:
anyAsBytes := []byte(r)
if json.Valid(anyAsBytes) {
_ = json.UnmarshalUseNumber(anyAsBytes, &target)
if err := json.UnmarshalUseNumber(anyAsBytes, &target); err != nil {
return false
}
return true
}
}

View File

@ -103,6 +103,10 @@ func Test_Strings(t *testing.T) {
}
t.AssertEQ(gconv.Strings(array), []string{"1", "2", "3"})
})
// https://github.com/gogf/gf/issues/1750
gtest.C(t, func(t *gtest.T) {
t.AssertEQ(gconv.Strings("123"), []string{"123"})
})
}
func Test_Slice_Interfaces(t *testing.T) {