10

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.

4
  • 1
    The code you posted makes not much sense (it has multiple compilation errors). Please explain in greater detail what you want (edit the question). Commented Jun 2, 2016 at 10:33
  • What is a map[string]string *byte supposed to be? Your syntax has too many errors to try and guess. Commented Jun 2, 2016 at 10:51
  • Please take a look at: blog.golang.org/json-and-go to further understand how to do what you want Commented Jun 2, 2016 at 11:16
  • There's no such thing as map[string,string]. Commented Jun 2, 2016 at 12:52

1 Answer 1

19

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.