[go-nuts] json unmarshal automatic type conversion issue

2016-12-13 Thread arunkumar
Hi gophers,

How to prevent json unmarshal from type conversion. From the below sample 
code i got the input string converted to float64


package main

import (
"fmt"
"encoding/json"
"reflect"
)

func main() {
var output interface{}
var input = "1"
fmt.Println(reflect.TypeOf(input))
json.Unmarshal([]byte(input), &output)
fmt.Println(reflect.TypeOf(output)) 
}


-- 

--
IMPORTANT: This is an e-mail from HiFX IT Media Services Pvt. Ltd. Its 
content are confidential to the intended recipient. If you are not the 
intended recipient, be advised that you have received this e-mail in error 
and that any use, dissemination, forwarding, printing or copying of this 
e-mail is strictly prohibited. It may not be disclosed to or used by anyone 
other than its intended recipient, nor may it be copied in any way. If 
received in error, please email a reply to the sender, then delete it from 
your system. 

Although this e-mail has been scanned for viruses, HiFX cannot ultimately 
accept any responsibility for viruses and it is your responsibility to scan 
attachments (if any).

​
Before you print this email or attachments, please consider the negative 
environmental impacts associated with printing.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] About the confusion caused by type conversion in golang

2021-01-27 Thread Arunkumar Gudelli
256 considered as `constant`. (untyped)
So when we try to convert to byte (which has a range from 0 to 255), it
will throw the overflow error.

Where `x := uint64(256)` we are giving a type to constant uint64.

y := byte(256) // Same error

so byte(uint64) will be zero without any errors.

regards,
Arun Gudelli
https://golangtutorial.dev/

On Thu, Jan 28, 2021 at 6:43 AM Barry Li  wrote:

> Some doubts about type conversion in go.
> In the following code, why can it be executed normally after passing the
> variable?
> The code is an error during the compilation phase.
>
> // The following two lines of code can be executed normally
> x := uint64(256)
> fmt.Println(byte(uint64(x))) // normal execution
>
> // The following code cannot be executed normally
> fmt.Println(byte(uint64(256))) // constant 256 overflows byte
>
> Can anyone help me answer it?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/401197ca-1cdc-45e8-9135-bafe0a300e21n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOOGzbXe84WeaN2rE7POow5gs_T5JikJfH9Vh8_EruEK_C3bKw%40mail.gmail.com.