diff --git a/tool/gabs.go b/tool/gabs.go index 1107a0c..70b4ef4 100644 --- a/tool/gabs.go +++ b/tool/gabs.go @@ -52,6 +52,7 @@ type FilterDataRule struct { // // Date : 2022/1/22 9:50 PM func NewDataFilter(source string, filterRule []*FilterDataRule, filterOption *FilterOption) *DataFilter { + source = fmt.Sprintf(`{"%v":%v}`, virtualRoot, source) if nil == filterOption { filterOption = &FilterOption{} } @@ -67,8 +68,8 @@ func NewDataFilter(source string, filterRule []*FilterDataRule, filterOption *Fi } // 去除末尾的 .[] for _, item := range filterRule { - item.MapKey = strings.TrimRight(item.MapKey, ".[]") - item.SourceKey = strings.TrimRight(item.SourceKey, ".[]") + item.MapKey = virtualRoot + "." + strings.TrimRight(item.MapKey, ".[]") + item.SourceKey = virtualRoot + "." + strings.TrimRight(item.SourceKey, ".[]") mapIsArr := df.isArrPath(item.MapKey) if !mapIsArr { df.filterRule = append(df.filterRule, item) @@ -146,7 +147,7 @@ func (df *DataFilter) Filter() (string, error) { } } df.logPrint(logLevelDebug, "过滤结果", df.rewriteResult) - return df.rewriteResult, nil + return gjson.Get(df.rewriteResult, virtualRoot).String(), nil } // isArrPath 是否为数组路径