forked from mirror/gjson
added result.Uint() function resolves #9
This commit is contained in:
parent
78babc5712
commit
a02d704254
|
@ -119,6 +119,7 @@ There are a variety of handy functions that work on a result:
|
||||||
```go
|
```go
|
||||||
result.Value() interface{}
|
result.Value() interface{}
|
||||||
result.Int() int64
|
result.Int() int64
|
||||||
|
result.Uint() uint64
|
||||||
result.Float() float64
|
result.Float() float64
|
||||||
result.String() string
|
result.String() string
|
||||||
result.Bool() bool
|
result.Bool() bool
|
||||||
|
|
15
gjson.go
15
gjson.go
|
@ -108,6 +108,21 @@ func (t Result) Int() int64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Uint returns an unsigned integer representation.
|
||||||
|
func (t Result) Uint() uint64 {
|
||||||
|
switch t.Type {
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
case True:
|
||||||
|
return 1
|
||||||
|
case String:
|
||||||
|
n, _ := strconv.ParseUint(t.Str, 10, 64)
|
||||||
|
return n
|
||||||
|
case Number:
|
||||||
|
return uint64(t.Num)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Float returns an float64 representation.
|
// Float returns an float64 representation.
|
||||||
func (t Result) Float() float64 {
|
func (t Result) Float() float64 {
|
||||||
switch t.Type {
|
switch t.Type {
|
||||||
|
|
Loading…
Reference in New Issue