diff --git a/util/gconv/gconv_slice_str.go b/util/gconv/gconv_slice_str.go index 48c3c168ca1..4c5a2aaf387 100644 --- a/util/gconv/gconv_slice_str.go +++ b/util/gconv/gconv_slice_str.go @@ -61,10 +61,7 @@ func Strings(any interface{}) []string { } case []uint8: if json.Valid(value) { - // Determine whether it is JSON in array format - if value[0] == '[' && value[len(value)-1] == ']' { - _ = json.UnmarshalUseNumber(value, &array) - } + _ = json.UnmarshalUseNumber(value, &array) } // Prevent strings from being null // See Issue 3465 for details @@ -83,10 +80,7 @@ func Strings(any interface{}) []string { case string: byteValue := []byte(value) if json.Valid(byteValue) { - // Determine whether it is JSON in array format - if byteValue[0] == '[' && byteValue[len(value)-1] == ']' { - _ = json.UnmarshalUseNumber(byteValue, &array) - } + _ = json.UnmarshalUseNumber(byteValue, &array) } // Prevent strings from being null // See Issue 3465 for details diff --git a/util/gconv/gconv_z_unit_slice_test.go b/util/gconv/gconv_z_unit_slice_test.go index 0760f212d56..0ab068b3f7a 100644 --- a/util/gconv/gconv_z_unit_slice_test.go +++ b/util/gconv/gconv_z_unit_slice_test.go @@ -315,6 +315,7 @@ func Test_Strings(t *testing.T) { t.AssertEQ(gconv.Strings(array), []string{"1", "2", "3"}) t.AssertEQ(gconv.Strings([]uint8(`["1","2"]`)), []string{"1", "2"}) + t.AssertEQ(gconv.Strings([]uint8(` ["1","2"] `)), []string{"1", "2"}) t.AssertEQ(gconv.Strings([][]byte{{byte(0)}, {byte(1)}}), []string{"\u0000", "\u0001"}) }) // https://github.com/gogf/gf/issues/1750