From 69066c35c24ff26babf8de47c8bbaebf5172b6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 28 Nov 2024 15:40:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E7=BB=84=E6=94=AF=E6=8C=81=E6=8C=89?= =?UTF-8?q?=E9=A1=B9=E5=B1=95=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gjson_hack/path.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gjson_hack/path.go b/gjson_hack/path.go index 6d8fab7..6ac654c 100644 --- a/gjson_hack/path.go +++ b/gjson_hack/path.go @@ -95,6 +95,7 @@ func doExpandPath(gjsonResult gjson.Result, rootPath string, hasChildren bool, p // 展开数组 for idx, itemRes := range arrayList { doExpandPath(itemRes, rootPath+"."+fmt.Sprintf("%v", idx), true, pathOption, pathResult) + doExpandPath(itemRes, rootPath+".{{idx}}", true, pathOption, pathResult) } } else { // 不展开数组 @@ -107,11 +108,12 @@ func doExpandPath(gjsonResult gjson.Result, rootPath string, hasChildren bool, p return } } - if strings.HasSuffix(rootPath, ".#") { + if strings.HasSuffix(rootPath, ".#") || strings.HasSuffix(rootPath, "{{idx}}") { // 处理不展开类型数组 return } if pathOption.OnlyFinalPath && hasChildren { + // 仅记录最终完整路径, 中间路径不记录 return } if _, exist := pathResult.ValueTable[rootPath]; !exist {