From 78b3ae43e5c1db9cde72890f5ef6fa1e2ff21387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 27 Aug 2023 00:22:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=BE=93=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8D=B3=E4=B8=BA=E6=95=B0=E7=BB=84,=20=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/parse.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tool/parse.go b/tool/parse.go index 79f231a..0128731 100644 --- a/tool/parse.go +++ b/tool/parse.go @@ -117,7 +117,11 @@ func GetJSONDataStructWithType(data string) ([]Field, error) { } pathList := make([]Field, 0) r := gjson.Parse(data) + inputIsArr := r.IsArray() r.ForEach(func(key, value gjson.Result) bool { + if inputIsArr && key.Int() > 0 { + return true + } if value.Value() == nil { pathList = append(pathList, Field{ Path: key.String(), @@ -183,6 +187,11 @@ func GetJSONDataStructWithType(data string) ([]Field, error) { return true }) + for idx := 0; idx < len(pathList); idx++ { + if inputIsArr && strings.HasPrefix(pathList[idx].Path, "0.") { + pathList[idx].Path = strings.Replace(pathList[idx].Path, "0.", "[].", 1) + } + } return pathList, nil }