mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 04:07:47 +08:00
Implemented gjson Example
1. New 2.NewWithTag 3.NewWithOptions
This commit is contained in:
parent
a887cedb99
commit
8cb6086f73
@ -72,3 +72,61 @@ func Example_newFromStructWithTag() {
|
||||
// 100
|
||||
// engineer
|
||||
}
|
||||
|
||||
func ExampleNew() {
|
||||
jsonContent := `{"name":"john", "score":"100"}`
|
||||
j := gjson.New(jsonContent)
|
||||
fmt.Println(j.Get("name"))
|
||||
fmt.Println(j.Get("score"))
|
||||
|
||||
// Output:
|
||||
// john
|
||||
// 100
|
||||
}
|
||||
|
||||
func ExampleNewWithTag() {
|
||||
type Me struct {
|
||||
Name string `tag:"name"`
|
||||
Score int `tag:"score"`
|
||||
Title string
|
||||
}
|
||||
me := Me{
|
||||
Name: "john",
|
||||
Score: 100,
|
||||
Title: "engineer",
|
||||
}
|
||||
j := gjson.NewWithTag(me, "tag")
|
||||
fmt.Println(j.Get("name"))
|
||||
fmt.Println(j.Get("score"))
|
||||
fmt.Println(j.Get("Title"))
|
||||
|
||||
// Output:
|
||||
// john
|
||||
// 100
|
||||
// engineer
|
||||
}
|
||||
|
||||
func ExampleNewWithOptions() {
|
||||
type Me struct {
|
||||
Name string `tag:"name"`
|
||||
Score int `tag:"score"`
|
||||
Title string
|
||||
}
|
||||
me := Me{
|
||||
Name: "john",
|
||||
Score: 100,
|
||||
Title: "engineer",
|
||||
}
|
||||
|
||||
j := gjson.NewWithOptions(me, gjson.Options{
|
||||
Tags: "tag",
|
||||
})
|
||||
fmt.Println(j.Get("name"))
|
||||
fmt.Println(j.Get("score"))
|
||||
fmt.Println(j.Get("Title"))
|
||||
|
||||
// Output:
|
||||
// john
|
||||
// 100
|
||||
// engineer
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user