From 23aa4c2f6f0745250b448eb9e00cda03080cde31 Mon Sep 17 00:00:00 2001 From: John Date: Wed, 24 Jan 2018 18:35:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Egparser=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geg/encoding/gparser.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/geg/encoding/gparser.go b/geg/encoding/gparser.go index 8a913bb77..859b677f1 100644 --- a/geg/encoding/gparser.go +++ b/geg/encoding/gparser.go @@ -43,7 +43,7 @@ func getWithPattern2() { } // 当键名存在"."号时,检索优先级:键名->层级,因此不会引起歧义 -func multiDots() { +func multiDots1() { data := `{ "users" : { @@ -58,6 +58,25 @@ func multiDots() { } } +func multiDots2() { + data := + `{ + "users" : { + "count" : { + "type1" : 1, + "type2" : 2 + }, + "count.type1" : 100 + } + }` + if p, e := gparser.LoadContent([]byte(data), "json"); e != nil { + glog.Error(e) + } else { + fmt.Println("Users Count:", p.Get("users.count.type1")) + fmt.Println("Users Count:", p.Get("users.count.type2")) + } +} + // 设置数据 func set1() { data := @@ -152,5 +171,5 @@ func convert() { } func main() { - convert() + multiDots2() } \ No newline at end of file