util/encoding/json/number.go

15 lines
211 B
Go
Raw Normal View History

2017-12-04 08:59:56 +00:00
package json
2017-12-04 09:31:23 +00:00
import (
"encoding/json"
"strconv"
)
2017-12-04 08:59:56 +00:00
func NumberToInt(n json.Number) (int, error) {
2017-12-04 09:31:23 +00:00
n64, err := strconv.ParseInt(n.String(), 10, 32)
2017-12-04 08:59:56 +00:00
if nil != err {
return 0, err
}
return int(n64), nil
}