我正在使用github.com/fatih/structs软件包将结构体的所有字段值转换成
[]interface{}
,并使用toValues()
函数。请参见这里。这个功能很好用,但最终我想通过使用csv软件包将这些值写入csv文件。csv.Write()
函数要求输入为[]string
。
简而言之:如何轻松地将toValues()
的输出转换为字符串数组?
fmt.Sprint(v)
更改为v.(string)
。 - Eric Lindsey[]interface{}
转换为[]string
。fmt.Sprintf("%v", inter)
生成单个string
,而不是[]string
。 - icza