Golang encoding/json.Number type example
package encoding/json
Golang encoding/json.Number type usage example
func (j *Json) Uint64() (uint64, error) {
switch j.data.(type) {
case json.Number: // <------ here
return strconv.ParseUint(j.data.(json.Number).String(), 10, 64)
case float32, float64:
return uint64(reflect.ValueOf(j.data).Float()), nil
case int, int8, int16, int32, int64:
return uint64(reflect.ValueOf(j.data).Int()), nil
case uint, uint8, uint16, uint32, uint64:
return reflect.ValueOf(j.data).Uint(), nil
}
return 0, errors.New("invalid value type")
}
Reference :
Advertisement
Something interesting
Tutorials
+34k Golang : Proper way to set function argument default value
+16k Golang : How to reverse elements order in map ?
+14.3k Golang : Get uploaded file name or access uploaded files
+17k Golang : How to save log messages to file?
+8.3k Golang : Auto-generate reply email with text/template package
+15.3k Golang : How to get Unix file descriptor for console and file
+28k Golang : Move file to another directory
+13k Swift : Convert (cast) Int to String ?
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+13.4k Golang : Generate Code128 barcode
+10.5k Swift : Convert (cast) String to Integer
+19.2k Golang : Delete item from slice based on index/key position