zoukankan      html  css  js  c++  java
  • Goframe的数组传值

    不知道为啥 

    直接

    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对象不能直接传递数组

    I can see a bigger world.
  • 相关阅读:
    TechRoad_oneStep_0509
    TechRoad_0417
    [Network] 判断设备是否能访问 Internet
    云原生相关知识点
    Algorithm: 多项式乘法 Polynomial Multiplication: 快速傅里叶变换 FFT / 快速数论变换 NTT
    Mac下配置Apache服务器
    解决antdv 中input每输入一个字符就失去焦点
    *装饰者模式(Decorator)
    *单例模式(singleton)
    ubuntu20.04 线缆已拔出
  • 原文地址:https://www.cnblogs.com/xuweiqiang/p/15347139.html
Copyright © 2011-2022 走看看