From 33815072ea915661837680b8c81cb9a4338549fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 27 Nov 2024 16:15:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=9A=E7=BB=B4=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gjson_hack/path_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/gjson_hack/path_test.go b/gjson_hack/path_test.go index d1211bf..65f6180 100644 --- a/gjson_hack/path_test.go +++ b/gjson_hack/path_test.go @@ -10,6 +10,7 @@ package gjson_hack import ( "encoding/json" "fmt" + "github.com/tidwall/gjson" "testing" ) @@ -49,8 +50,27 @@ func TestPathOnlyFinallyPath(t *testing.T) { "email": "xxx@xxx.com", }, "sex": "man", + "user_list": [][]map[string]any{ + []map[string]any{ + {"name": "zhang", "age": 10}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + []map[string]any{ + {"name": "zhang", "age": 20}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + []map[string]any{ + {"name": "zhang", "age": 30}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + }, } byteData, _ := json.Marshal(mapData) + fmt.Println(gjson.GetBytes(byteData, "user_list.#.#.age")) + fmt.Println(gjson.GetBytes(byteData, "user_list.0.0.age")) pathRes, err := Path(string(byteData), &PathOption{ UnfoldArray: false, MaxDeep: 0, @@ -77,6 +97,23 @@ func TestPathOnlyFinallyPathWithUnfoldArray(t *testing.T) { "email": "xxx@xxx.com", }, "sex": "man", + "user_list": [][]map[string]any{ + []map[string]any{ + {"name": "zhang", "age": 10}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + []map[string]any{ + {"name": "zhang", "age": 10}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + []map[string]any{ + {"name": "zhang", "age": 10}, + {"name": "li", "age": 20}, + {"name": "wang", "age": 30}, + }, + }, } byteData, _ := json.Marshal(mapData) pathRes, err := Path(string(byteData), &PathOption{