util-go/encoding/json/number.go
crusader 9343327d37 ing
2018-07-04 16:43:17 +09:00

19 lines
310 B
Go

package json
import (
"encoding/json"
"strconv"
)
func NumberToInt(n json.Number) (int, error) {
n64, err := strconv.ParseInt(n.String(), 10, 32)
if nil != err {
return 0, err
}
return int(n64), nil
}
func NumberToInt64(n json.Number) (int64, error) {
return strconv.ParseInt(n.String(), 10, 64)
}