From 014534d546462b6054da0a90689494217a722466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 10 Sep 2021 18:05:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json_tool/filter.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/json_tool/filter.go b/json_tool/filter.go index 0bdc292..b418b8c 100644 --- a/json_tool/filter.go +++ b/json_tool/filter.go @@ -58,9 +58,8 @@ func (f *Filter) Result() (*DynamicJSON, error) { // 为数组的处理 pathArr := strings.Split(extraDataPath, ".[].") val := gjson.Get(source, pathArr[0]) - isComplexType := val.IsArray() || val.IsObject() if len(pathArr) == 1 { - result.SetValue(newDataPath, val.Value(), isComplexType) + f.SetValue(result, newDataPath, val.Value(), false, 0) continue } // 支持list再抽取一层,处于性能考虑,这么限制,不做递归无限深度处理 @@ -79,6 +78,18 @@ func (f *Filter) Result() (*DynamicJSON, error) { return result, nil } +// SetValue 设置值 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 12:14 下午 2021/9/10 +func (f *Filter) SetValue(result *DynamicJSON, path string, val interface{}, isSetSlice bool, sliceIndex int) { + if !isSetSlice { + result.SetValue(path, val, false) + return + } +} + // isLegalData 判断是否能转换成json结构, 只有slice/map/struct/能转换成slice或map的[]byte是合法的 // // Author : go_developer@163.com<白茶清欢>