-
Notifications
You must be signed in to change notification settings - Fork 3
/
field.go
47 lines (38 loc) · 1.1 KB
/
field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package jsonKit
import "github.com/tidwall/gjson"
// GetStringField
/*
@param path 如果是嵌套的内部字段,可以通过'.'组合
*/
func GetStringField(jsonData []byte, path string) string {
result := gjson.GetBytes(jsonData, path)
return result.String()
}
func GetStringFieldFromString(jsonStr, path string) string {
result := gjson.Get(jsonStr, path)
return result.String()
}
func GetInt64Field(jsonData []byte, path string) int64 {
result := gjson.GetBytes(jsonData, path)
return result.Int()
}
func GetInt64FieldFromString(jsonStr, path string) int64 {
result := gjson.Get(jsonStr, path)
return result.Int()
}
func GetFloat64Field(jsonData []byte, path string) float64 {
result := gjson.GetBytes(jsonData, path)
return result.Float()
}
func GetFloat64FieldFromString(jsonStr, path string) float64 {
result := gjson.Get(jsonStr, path)
return result.Float()
}
func GetBoolField(jsonData []byte, path string) bool {
result := gjson.GetBytes(jsonData, path)
return result.Bool()
}
func GetBoolFieldFromString(jsonStr, path string) bool {
result := gjson.Get(jsonStr, path)
return result.Bool()
}