From ce1e7fe9dadbd90fcf5b565cc69d5e600be20c4e 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, 30 Nov 2024 17:31:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DmapConfig=E5=A4=84=E7=90=86?= =?UTF-8?q?=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 --- gjson_hack/path.go | 2 +- gjson_hack/path_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gjson_hack/path.go b/gjson_hack/path.go index 2a4bc38..57bf1ea 100644 --- a/gjson_hack/path.go +++ b/gjson_hack/path.go @@ -151,7 +151,7 @@ func ExpandArrayPath(jsonStr string, pathConfig string, mapConfig string, expend expendArrayResult.PathMap[pathConfig] = mapConfig return nil } - mapConfigArr := strings.Split(pathConfig, ArrayIdxTpl) + mapConfigArr := strings.Split(mapConfig, ArrayIdxTpl) mapConfigArr[0] = strings.TrimSuffix(mapConfigArr[0], ".") mapSuffixPathTpl := strings.TrimPrefix(strings.Join(mapConfigArr[1:], ArrayIdxTpl), ".") diff --git a/gjson_hack/path_test.go b/gjson_hack/path_test.go index 8bd5f64..e607098 100644 --- a/gjson_hack/path_test.go +++ b/gjson_hack/path_test.go @@ -171,8 +171,8 @@ func TestExpandArrayPath(t *testing.T) { PathMap: nil, } ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.age", "a.{{idx}}.{{idx}}.b", pathExpendRes) - ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.name", "a.{{idx}}.{{idx}}.c", pathExpendRes) - ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.sex", "a.{{idx}}.{{idx}}.c", pathExpendRes) + ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.name", "e.{{idx}}.{{idx}}.c", pathExpendRes) + ExpandArrayPath(jsonStr, "user_list.{{idx}}.{{idx}}.sex", "f.{{idx}}.{{idx}}.c", pathExpendRes) res := "" for _, item := range pathExpendRes.PathList { res, _ = sjson.Set(res, pathExpendRes.PathMap[item], gjson.Get(jsonStr, item).Value())