From dfc58c7052a1a8ecf9fd91a9dc1521278a701261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 22 Jan 2022 21:02:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlist=E6=8F=90=E5=8F=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json_tool/filter.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/json_tool/filter.go b/json_tool/filter.go index e51d35f..d2be397 100644 --- a/json_tool/filter.go +++ b/json_tool/filter.go @@ -75,12 +75,12 @@ func (f *Filter) Result() (*DynamicJSON, error) { } // 支持list再抽取一层,处于性能考虑,这么限制,不做递归无限深度处理 // 还能继续抽取,就认为是 []map[string]interface{} - ketList := strings.Split(pathArr[1], ".") + keyList := strings.Split(pathArr[1], ".") for idx, item := range val.Array() { data := item.Map() - for _, key := range ketList { - if v, exist := data[key]; exist { - result.SetValue(strings.ReplaceAll(newDataRule.MapKey, "[]", fmt.Sprintf("[%d]", idx)), data[key].Value(), v.IsObject() || v.IsArray()) + for _, key := range keyList { + if _, exist := data[key]; exist { + result.SetValue(strings.ReplaceAll(newDataRule.MapKey, "[]", fmt.Sprintf("[%d]", idx)), data[key].String(), newDataRule.IsComplexType) } else { // 结果集中不存在对应key,设置默认值 result.SetValue(strings.ReplaceAll(newDataRule.MapKey, "[]", fmt.Sprintf("[%d]", idx)), newDataRule.DefaultValue, newDataRule.IsComplexType)