From 4608f898fa4343ebd2f8e547f7ceccd195885d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 9 Sep 2021 14:31:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8Djson=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json/json_test.go | 76 ------------------------------------ {json => json_tool}/build.go | 8 ++-- {json => json_tool}/parse.go | 4 +- 3 files changed, 6 insertions(+), 82 deletions(-) delete mode 100644 json/json_test.go rename {json => json_tool}/build.go (98%) rename {json => json_tool}/parse.go (98%) diff --git a/json/json_test.go b/json/json_test.go deleted file mode 100644 index 3649588..0000000 --- a/json/json_test.go +++ /dev/null @@ -1,76 +0,0 @@ -// Package json... -// -// Description : json... -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 2021-03-10 11:44 下午 -package json - -import ( - "fmt" - "testing" -) - -// TestJSON ... -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 10:58 下午 2021/3/14 -func TestJSON(t *testing.T) { - tree := NewDynamicJSON() - fmt.Println(tree.extraSliceIndex("[200]")) - tree.SetValue("extra.height.value", 180, false) - tree.SetValue("extra.height.unit.use", "cm", false) - tree.SetValue("extra.height.unit.open", "1", false) - tree.SetValue("name", "zhangdeman", false) - tree.SetValue("good.name", "good", false) - tree.SetValue("work", "111", false) - tree.SetValue("good.price", "180", false) - tree.SetValue("good.unit", "$", false) - tree.SetValue("slice.[0].name", "zhang", false) - tree.SetValue("slice.[0].age", 30, false) - tree.SetValue("slice.[1].name", "de", false) - tree.SetValue("slice.[2].name", "man", false) - tree.SetValue("slice.[3]", "zhangdeman", false) - fmt.Println(tree.String()) - tree = NewDynamicJSON() - tree.SetValue("[0]", "zhang", false) - tree.SetValue("[1]", "de", false) - tree.SetValue("[2]", "man", false) - fmt.Println(tree.String()) -} - -// TestType 判断数据类型断言 -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 10:59 下午 2021/3/14 -func TestType(t *testing.T) { - -} - -// TestSelect 测试动态选择字段 -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 9:47 下午 2021/4/13 -func TestSelect(t *testing.T) { - source := map[string]interface{}{ - "name": "zhangdeman", - "extra": map[string]interface{}{ - "age": 18, - "height": 180, - "slice": []int{1, 2, 3}, - }, - "slice": []int{1, 2, 3}, - "map": map[string]interface{}{"a": 1, "b": 2, "c": 4}, - "table": []map[string]interface{}{ - {"name": "alex", "age": 18, "number": 1}, - {"name": "bob", "age": 28, "number": 2}, - }, - } - pathList := []string{"name", "extra.age", "slice", "map", "table.[].name|number|test"} - r, e := NewParseJSONTree(source).Parse(pathList) - fmt.Println(r.String(), e) -} diff --git a/json/build.go b/json_tool/build.go similarity index 98% rename from json/build.go rename to json_tool/build.go index 3002cd0..e0b0a04 100644 --- a/json/build.go +++ b/json_tool/build.go @@ -1,11 +1,11 @@ -// Package json... +// Package json_tool... // // Description : 动态构建json // // Author : go_developer@163.com<白茶清欢> // // Date : 2021-03-10 10:26 下午 -package json +package json_tool import ( "encoding/json" @@ -19,7 +19,7 @@ import ( ) const ( - // PathSplit json 路径的分割符 + // PathSplit json_tool 路径的分割符 PathSplit = "." ) @@ -29,7 +29,7 @@ const ( // // Date : 10:33 下午 2021/3/10 type JSONode struct { - Key string // json key + Key string // json_tool key Value interface{} // 对应的值 Child []*JSONode // 子节点 IsRoot bool // 是否根节点 diff --git a/json/parse.go b/json_tool/parse.go similarity index 98% rename from json/parse.go rename to json_tool/parse.go index 97117a2..64a4f3c 100644 --- a/json/parse.go +++ b/json_tool/parse.go @@ -1,11 +1,11 @@ -// Package json ... +// Package json_tool ... // // Description : 将复杂数据结构转化为 JSONNode 树 // // Author : go_developer@163.com<白茶清欢> // // Date : 2021-03-14 10:40 下午 -package json +package json_tool import ( "encoding/json"