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