我正在尝试创建地图片段。尽管代码可以很好地编译,但在下面出现运行时错误:mapassign1: runtime·panicstring("assignment to entry in nil map");我尝试制作一个Map数组,每个Map包含两个指标,即“ Id”和“ Investor”。我的代码如下所示:for _, row := range rows { var inv_ids []string var inv_names []string //create arrays of data from MySQLs GROUP_CONCAT function inv_ids = strings.Split(row.Str(10), ",") inv_names = strings.Split(row.Str(11), ",") length := len(inv_ids); invs := make([]map[string]string, length) //build map of ids => names for i := 0; i < length; i++ { invs[i] = make(map[string]string) invs[i]["Id"] = inv_ids[i] invs[i]["Investor"] = inv_names[i] }//for //build Message and return msg := InfoMessage{row.Int(0), row.Int(1), row.Str(2), row.Int(3), row.Str(4), row.Float(5), row.Float(6), row.Str(7), row.Str(8), row.Int(9), invs} return(msg) } //for我最初认为类似下面的内容会起作用,但是也不能解决该问题。有任何想法吗?invs := make([]make(map[string]string), length)
1 回答
- 1 回答
- 0 关注
- 260 浏览
添加回答
举报
0/150
提交
取消