diff --git a/array.go b/array.go index 0d5f8a8..43fef7a 100644 --- a/array.go +++ b/array.go @@ -289,10 +289,38 @@ func (at *Array) Has(input interface{}) int { // Author : go_developer@163.com<白茶清欢> // // Date : 16:57 2023/9/28 -func (at *Array) ToString() string { +func (at *Array) ToString() StringResult { if at.IsNil() { - return "" + return StringResult{ + Value: "", + Err: nil, + } + } + byteData, err := json.Marshal(at.convertResult) + return StringResult{ + Value: string(byteData), + Err: err, + } +} + +// ToStringWithSplit 数组按照指定分隔符转为字符串 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:42 2023/10/25 +func (at *Array) ToStringWithSplit(split string) StringResult { + if at.IsNil() { + return StringResult{ + Value: "", + Err: nil, + } + } + strList := make([]string, 0) + for _, item := range at.convertResult { + strList = append(strList, fmt.Sprintf("%v", item)) + } + return StringResult{ + Value: strings.Join(strList, split), + Err: nil, } - byteData, _ := json.Marshal(at.convertResult) - return string(byteData) }