github.com/zhangdapeng520/zdpgo_json@v0.1.5/examples/query/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/zhangdapeng520/zdpgo_json" 7 ) 8 9 type account struct { 10 Email string `json:"email"` 11 password string `json:"password"` // 不会处理私有变量 12 Money float64 `json:"money"` 13 } 14 15 type user struct { 16 Name string 17 Age int 18 Roles []string 19 Skill map[string]float64 20 Account account 21 } 22 23 func main() { 24 a := account{ 25 Email: "张大鹏", 26 password: "123456", 27 Money: 100.5, 28 } 29 u := user{ 30 Name: "张大鹏", 31 Age: 27, 32 Roles: []string{"Owner", "Master"}, // 处理切片 33 Account: a, 34 } 35 36 j := zdpgo_json.New() 37 38 // 序列化 39 jsonData, err := j.Dumps(u) 40 if err != nil { 41 fmt.Println(err) 42 } 43 fmt.Println(jsonData) 44 fmt.Println("the json string :", jsonData) 45 46 // Get查询 47 money := j.Query.Get(jsonData, "Account.money") 48 fmt.Println("Get查询:", money, money.Float()) 49 }