Skip to content

Commit e80c8df

Browse files
committed
优化数组转对象,则获取数组的第一个元素进行转换
1 parent db75eda commit e80c8df

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

conv_base.go

+7
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,13 @@ func copyStruct(result reflect.Value, original reflect.Value, params ...Unmarsha
670670
}
671671

672672
switch original.Kind() {
673+
674+
case reflect.Slice:
675+
//如果是数组转对象,则获取数组的第一个元素进行转换
676+
if original.Len() > 0 {
677+
return copyStruct(result, original.Index(0))
678+
}
679+
673680
case reflect.Struct:
674681
fieldMap := make(map[string]reflect.Value)
675682
tagMaps := make([]map[string]reflect.Value, len(tags))

0 commit comments

Comments
 (0)