mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
新增gparser示例
This commit is contained in:
@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user