不知道为啥
直接
columns := r.Get("columns")
拿到参数以后需要:
tmpList := gconv.Map(columns) var columnList []map[string]interface{} for _, v := range tmpList { if len(gconv.Map(v)) != 0 { columnList = append(columnList, gconv.Map(v)) } } // columnList := gconv.SliceMap(columns) //为啥不能直接转换
有时候会被转为map参数值
程序:
// 对于传入数组元素取值 fmt.Println("columns = ",columns) tmpList := gconv.Map(columns) fmt.Println("tmpList = ",tmpList) var columnList []map[string]interface{} for _, v := range tmpList { if len(gconv.Map(v)) != 0 { columnList = append(columnList, gconv.Map(v)) } } fmt.Println("columnList = ",columnList) fmt.Println("slice map columnList = ",gconv.SliceMap(columns))
传递参数:
"columns":{"0":{"name":"jack"},"1":{"name":"rose"}}
打印值:
columns = map[0:map[name:jack] 1:map[name:rose]] tmpList = map[0:map[name:jack] 1:map[name:rose]] columnList = [map[name:jack] map[name:rose]] slice map columnList = [map[0:map[name:jack] 1:map[name:rose]]]
更换一种参数
"columns":[{"name":"jack"},{"name":"rose"}]}
打印值:
columns = [map[name:jack] map[name:rose]] tmpList = map[{"name":"jack"}:map[name:rose]] columnList = [map[name:rose]] slice map columnList = [map[name:jack] map[name:rose]]
此时拿到的原始值是数组
总结:
对于数组传值直接 gconv.Map会丢失元素
对于对象传值,sliceMap会丢失元素
难道只能传递一个map对象不能直接传递数组