1. 首页
  2. 主题
  3. Go语言

多维map中key的问题

jayxtt999 · · 1188 次点击
如数据类型是这种二维数组(示意) ![image.png](https://static.studygolang.com/211216/4cfef7910fac1fc571299dae6a17bb18.png) 如果使用map则可能写成如下 ``` where := make(map[int]map[string]string) where[0] = make(map[string]string) where[0]["key"] = "value" ``` 似乎必须得指定一个key 尝试过使用切片 然后append追加的方式是实现,也挺繁琐 ``` where := make([]map[string]string,0) _map := make(map[string]string) _map["key"] = "value" where := append(where,_map) ``` 还有一个附加的场景是 这个map可以需要经过多个方法去组装,就导致传递很麻烦。目前用一个*i 传递做key。然后每赋值一次i++,后续继续这样组装 有没有大佬指点一下有无其它方便维护且易于阅读的方式去实现?
``` interface{}[]{ map[string]interface{}{"key":"value"}, map[string]interface{}{"key2":"value2"}, } ``` 但我绝对不会去这么写。
#2
更多评论
类似php可以这样玩 ``` $where = []; $where[] = ["key"=>"value"]; $where[] = ["key"=>"value"]; $where[] = ["key"=>"value"]; $where[] = ["key"=>"value"]; ```
#1

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中