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)