mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
Implemented gjson Example
1.SetSplitChar
This commit is contained in:
@ -32,27 +32,6 @@ func Example_patternGet() {
|
||||
// John Score: 99.5
|
||||
}
|
||||
|
||||
func Example_patternCustomSplitChar() {
|
||||
data :=
|
||||
`{
|
||||
"users" : {
|
||||
"count" : 2,
|
||||
"list" : [
|
||||
{"name" : "Ming", "score" : 60},
|
||||
{"name" : "John", "score" : 99.5}
|
||||
]
|
||||
}
|
||||
}`
|
||||
if j, err := gjson.DecodeToJson(data); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
j.SetSplitChar('#')
|
||||
fmt.Println("John Score:", j.Get("users#list#1#score").Float32())
|
||||
}
|
||||
// Output:
|
||||
// John Score: 99.5
|
||||
}
|
||||
|
||||
func Example_patternViolenceCheck() {
|
||||
data :=
|
||||
`{
|
||||
|
||||
48
encoding/gjson/gjson_z_example_test.go
Normal file
48
encoding/gjson/gjson_z_example_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package gjson_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
)
|
||||
|
||||
func ExampleJson_SetSplitChar() {
|
||||
data :=
|
||||
`{
|
||||
"users" : {
|
||||
"count" : 2,
|
||||
"list" : [
|
||||
{"name" : "Ming", "score" : 60},
|
||||
{"name" : "John", "score" : 99.5}
|
||||
]
|
||||
}
|
||||
}`
|
||||
if j, err := gjson.DecodeToJson(data); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
j.SetSplitChar('#')
|
||||
fmt.Println("John Score:", j.Get("users#list#1#score").Float32())
|
||||
}
|
||||
// Output:
|
||||
// John Score: 99.5
|
||||
}
|
||||
|
||||
func ExampleJson_SetViolenceCheck() {
|
||||
data :=
|
||||
`{
|
||||
"users" : {
|
||||
"count" : 2,
|
||||
"list" : [
|
||||
{"name" : "Ming", "score" : 60},
|
||||
{"name" : "John", "score" : 99.5}
|
||||
]
|
||||
}
|
||||
}`
|
||||
if j, err := gjson.DecodeToJson(data); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
j.SetViolenceCheck(false)
|
||||
fmt.Println("John Score:", j.Get("users.list.1.score").Float32())
|
||||
}
|
||||
// Output:
|
||||
// John Score: 99.5
|
||||
}
|
||||
Reference in New Issue
Block a user