gjson的二次处理 #6

Merged
zhangdeman merged 6 commits from feature/json into master 2024-11-29 17:30:35 +08:00
Showing only changes of commit 69066c35c2 - Show all commits

View File

@ -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 {