我正在尝试创建一片地图。虽然代码编译得很好,但我得到下面的运行时错误:
mapassign1: runtime·panicstring("assignment to entry in nil 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)