util-go/encoding/json/number.go

15 lines
211 B
Go
Raw Permalink Normal View History

2018-08-22 08:59:12 +00:00
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
}