What happens to my original data in the variable str
here?
After converting to the struct the length of bytes is 6
And the value of byte don't match ascii code of 1, 2, 3, 4, 5, 6, 7, 8 at all
package main
import (
"encoding/json"
"fmt"
)
type Encrypt struct {
Bytes []byte `json:"bytes"`
}
func main(){
str := "12345678"
raw := fmt.Sprintf("{\"bytes\":%s}", str)
var encrypt = Encrypt{}
fmt.Println([]byte(raw)[0])
err := json.Unmarshal([]byte(raw), &encrypt)
if err != nil{
fmt.Println(err)
return
}
fmt.Println("final result")
fmt.Println(len(encrypt.Bytes))
fmt.Println(string(encrypt.Bytes))
for _, b := range encrypt.Bytes{
fmt.Print(b)
fmt.Print(" ")
}
fmt.Print("\n")
}