diff --git a/json.go b/json.go index 8218b55..bc225d1 100644 --- a/json.go +++ b/json.go @@ -123,6 +123,55 @@ func (oj *ownJSON) Transition(input interface{}, receiver interface{}) error { return oj.UnmarshalWithNumber(oj.MarshalForByte(input), receiver) } +// TransitionIgnoreError ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 16:57 2024/1/10 +func (oj *ownJSON) TransitionIgnoreError(input interface{}, receiver interface{}) { + _ = oj.UnmarshalWithNumber(oj.MarshalForByte(input), receiver) +} + +// MergeDataForMap 合并数据到map +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 16:48 2024/1/10 +func (oj *ownJSON) MergeDataForMap(ignoreError bool, dataList ...interface{}) (map[string]interface{}, error) { + res := make(map[string]interface{}) + for _, data := range dataList { + if nil == data { + continue + } + var ( + err error + itemRes map[string]interface{} + ) + + if err = oj.Transition(data, &itemRes); nil != err { + if ignoreError { + continue + } + return res, err + } + + for k, v := range itemRes { + res[k] = v + } + } + return res, nil +} + +// MergeDataForMapIgnoreError 多个数据合并到一个Map +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:00 2024/1/10 +func (oj *ownJSON) MergeDataForMapIgnoreError(dataList ...interface{}) map[string]interface{} { + res, _ := oj.MergeDataForMap(true, dataList) + return res +} + // ConsoleOutput ... // // Author : go_developer@163.com<白茶清欢>