Golang encoding/json.Number.Int64 function example

package encoding/json

Int64 returns the number as an int64.

Golang encoding/json.Number.Int64 function usage example

 func (j *Json) Float64() (float64, error) {

 switch j.data.(type) {
 case json.Number:
 return j.data.(json.Number).Int64() // <---- here 

 case float32, float64:
 return reflect.ValueOf(j.data).Float(), nil

 case int, int8, int16, int32, int64:
 return float64(reflect.ValueOf(j.data).Int()), nil

 case uint, uint8, uint16, uint32, uint64:
 return float64(reflect.ValueOf(j.data).Uint()), nil
 }
 return 0, errors.New("invalid value type")
  }

Reference :

http://golang.org/pkg/encoding/json/#Number.Int64

Advertisement