From 2230411f76ecf42a87b706bf09c6a91cc10a9569 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, 2 Sep 2023 22:14:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5=E8=99=9A=E6=8B=9F=E8=8A=82?= =?UTF-8?q?=E7=82=B9,=20=E5=BD=92=E4=B8=80=E5=8C=96=E5=A4=84=E7=90=86list?= =?UTF-8?q?=E4=B8=8Emap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/gabs.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 是否为数组路径