arrays - appending non slice to map of slices -


my current code this:

name := "john" id := "1234" c := make(map[string][]string)  c["d"] = make([]string, len(d)) c["l"] = make([]string, len(l))  copy(c["d"], d) copy(c["l"], l) c["test"] = name c["id"] = id 

assuming d & l both []string. go not let me this. there way able achieve json this:

{ "name": "john", "id": "1234", "d": [ 123, 456 ], "l": [ 123, 456 ] }

  1. you need use map[string]interface{} instead.
  2. also don't need copy slices.

example map[string]interface{}:

name := "john" id := "1234" l, d := []string{"123", "456"}, []string{"789", "987"} c := map[string]interface{}{     "d":    d,     "l":    l,     "test": name,     "id":   id, } 

playground


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -