增加转为字符串

This commit is contained in:
白茶清欢 2023-09-28 17:01:42 +08:00
parent faafa8ee2a
commit 9f0b7008a4

View File

@ -201,6 +201,22 @@ func (at *Array) Convert() ([]interface{}, error) {
at.itemType = reflect.Interface at.itemType = reflect.Interface
at.convertResult = make([]interface{}, len(val)) at.convertResult = make([]interface{}, len(val))
copy(at.convertResult, val) copy(at.convertResult, val)
case []struct{}:
at.isSimpleSlice = false
at.itemType = reflect.Interface
at.convertResult = make([]interface{}, len(val))
for i := 0; i < len(val); i++ {
at.convertResult[i] = val[i]
}
case []map[string]interface{}:
at.isSimpleSlice = false
at.itemType = reflect.Interface
at.convertResult = make([]interface{}, len(val))
for i := 0; i < len(val); i++ {
at.convertResult[i] = val[i]
}
default:
} }
return at.convertResult, nil return at.convertResult, nil
} }
@ -267,3 +283,16 @@ func (at *Array) Has(input interface{}) int {
} }
return -1 return -1
} }
// ToString ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 16:57 2023/9/28
func (at *Array) ToString() string {
if at.IsNil() {
return ""
}
byteData, _ := json.Marshal(at.convertResult)
return string(byteData)
}