- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonvalue.go
More file actions
Latest commit
131 lines (109 loc) · 2.3 KB
/
Copy pathjsonvalue.go
File metadata and controls
131 lines (109 loc) · 2.3 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
@Time : 2019-03-26 16:36
@Author : seefan
@File : jsonreader
@Software: jsonreader
*/
package jsonreader
import (
"strconv"
"time"
)
//扩展值,原始类型为 string
typeJsonValuestring
//返回 string 的值
func (vJsonValue) String() string {
returnstring(v)
}
//返回 int64 的值
func (vJsonValue) Int64() int64 {
iff, e:=strconv.ParseInt(string(v), 10, 64); e==nil {
returnf
}
return0
}
//返回 int32 的值
func (vJsonValue) Int32() int32 {
returnint32(v.Int64())
}
//返回 int16 的值
func (vJsonValue) Int16() int16 {
returnint16(v.Int64())
}
//返回 int8 的值
func (vJsonValue) Int8() int8 {
returnint8(v.Int64())
}
//返回 int 的值
func (vJsonValue) Int() int {
returnint(v.Int64())
}
//返回 uint64 的值
func (vJsonValue) UInt64() uint64 {
iff, e:=strconv.ParseUint(string(v), 10, 64); e==nil {
returnf
}
return0
}
//返回 uint32 类型的值
func (vJsonValue) UInt32() uint32 {
returnuint32(v.UInt64())
}
//返回 uint16 类型的值
func (vJsonValue) UInt16() uint16 {
returnuint16(v.UInt64())
}
//返回 uint8 类型的值
func (vJsonValue) UInt8() uint8 {
returnuint8(v.UInt64())
}
//返回 byte 类型的值
func (vJsonValue) Byte() byte {
returnv.UInt8()
}
//返回 uint 类型的值
func (vJsonValue) UInt() uint {
returnuint(v.UInt64())
}
//返回 float64 类型的值
func (vJsonValue) Float64() float64 {
iff, e:=strconv.ParseFloat(string(v), 64); e==nil {
returnf
}
return0
}
//返回 float32 类型的值
func (vJsonValue) Float32() float32 {
returnfloat32(v.Float64())
}
//返回 bool 类型的值
func (vJsonValue) Bool() bool {
returnv=="true"
}
//return is null
// v=='null'
func (vJsonValue) IsNull() bool {
returnv=="null"
}
//返回 time.Time 类型的值
func (vJsonValue) Time() time.Time {
returntime.Unix(v.Int64(), 0)
}
//返回 time.Duration 类型的值
func (vJsonValue) Duration() time.Duration {
returntime.Duration(v.Int64())
}
//返回 []byte 类型的值
func (vJsonValue) Bytes() []byte {
return []byte(v)
}
//判断是否为空
func (vJsonValue) IsEmpty() bool {
returnv==""||v.IsNull()
}
func (vJsonValue) ParseJsonObject() *JsonObject {
returnParseJsonObject([]byte(v))
}
func (vJsonValue) ParseJsonArray() *JsonArray {
returnParseJsonArray([]byte(v))
}