I want to convert byte array to map[string,string] using golang. I tried this:
var byte := json.Marshal(input)
var map := make(map[string]string *byte) // NOT WORKING
if byte holds value like {\"hello\":\"world\",...} How to create the map from byte array
Please help.
Create a map in Golang[string] - indicates that keys of the map are of string type. float32 - indicates that values of the map are of float type. {Golang", "Java", "Python"} - keys of the map. {85, 80, 81} - values of the map.
The byte type in Golang is an alias for the unsigned integer 8 type ( uint8 ). The byte type is only used to semantically distinguish between an unsigned integer 8 and a byte. The range of a byte is 0 to 255 (same as uint8 ).
map[string]interface{} is a map whose keys are strings and values are any type.
Byte. A byte in Go is an unsigned 8-bit integer. That means it has a limit of 0–255 in the numerical range. type byte = uint8. According to Go documentation, Byte is an alias for uint8 and is the same as uint8 in all ways.
You probably want to do something like
m := make(map[string]string)
err := json.Unmarshal(input, &m)
This creates a new map[string]string and unmarshals a byte array into it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With