-
Notifications
You must be signed in to change notification settings - Fork 3
/
fieldSlice.go
75 lines (58 loc) · 1.55 KB
/
fieldSlice.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package jsonKit
import "github.com/tidwall/gjson"
func GetStringSliceField(jsonData []byte, path string) (s []string) {
result := gjson.GetBytes(jsonData, path)
for _, item := range result.Array() {
s = append(s, item.String())
}
return
}
func GetStringSliceFieldFromString(jsonStr, path string) (s []string) {
result := gjson.Get(jsonStr, path)
for _, item := range result.Array() {
s = append(s, item.String())
}
return
}
func GetInt64SliceField(jsonData []byte, path string) (s []int64) {
result := gjson.GetBytes(jsonData, path)
for _, item := range result.Array() {
s = append(s, item.Int())
}
return
}
func GetInt64SliceFieldFromString(jsonStr, path string) (s []int64) {
result := gjson.Get(jsonStr, path)
for _, item := range result.Array() {
s = append(s, item.Int())
}
return
}
func GetFloat64SliceField(jsonData []byte, path string) (s []float64) {
result := gjson.GetBytes(jsonData, path)
for _, item := range result.Array() {
s = append(s, item.Float())
}
return
}
func GetFloat64SliceFieldFromString(jsonStr, path string) (s []float64) {
result := gjson.Get(jsonStr, path)
for _, item := range result.Array() {
s = append(s, item.Float())
}
return
}
func GetBoolSliceField(jsonData []byte, path string) (s []bool) {
result := gjson.GetBytes(jsonData, path)
for _, item := range result.Array() {
s = append(s, item.Bool())
}
return
}
func GetBoolSliceFieldFromString(jsonStr, path string) (s []bool) {
result := gjson.Get(jsonStr, path)
for _, item := range result.Array() {
s = append(s, item.Bool())
}
return
}