From d98822a5ee78a12129d11952b856774d81e2eab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BE=B7=E6=BB=A1?= Date: Tue, 13 Apr 2021 22:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8B=BC=E5=86=99=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json/json_test.go | 3 ++- json/parse.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/json/json_test.go b/json/json_test.go index 0d1e175..7e4e4b0 100644 --- a/json/json_test.go +++ b/json/json_test.go @@ -63,8 +63,9 @@ func TestSelect(t *testing.T) { "slice": []int{1, 2, 3}, }, "slice": []int{1, 2, 3}, + "map": map[string]interface{}{"a": 1, "b": 2, "c": 4}, } - pathList := []string{"name", "extra.age", "slice"} + pathList := []string{"name", "extra.age", "slice", "map"} r, e := NewParseJSONTree(source).Parse(pathList) fmt.Println(r.String(), e) } diff --git a/json/parse.go b/json/parse.go index db4c0ef..bf33033 100644 --- a/json/parse.go +++ b/json/parse.go @@ -55,13 +55,13 @@ func (pjt *ParseJSONTree) Parse(pathList []string) (*DynamicJSON, error) { pathArr := strings.Split(path, "[]") for idx, item := range pathArr { val := gjson.Get(source, item) - isComplextType := val.IsArray() + isComplexType := val.IsArray() if len(pathArr)-1 == idx { // 当前是最后一项,说明不是数组 - if isComplextType { + if isComplexType { fmt.Println("这是一个数组") } - result.SetValue(item, val.Raw, isComplextType) + result.SetValue(item, val.Raw, isComplexType) continue } }