请帮助我,如何从查询中检查相同的值
并在golang或python中捕获第一个值

{
“数据”:[
“1234567001”,
“1234567001”,
“1234567001”,
“1234567001”,
“4567898001”,
“4567898001”,
“4567898001”
]
}

如何使用go lang从数据中获取2个不同的值

vals := []interface{}{}
for _, row := range result {
    nobil := row.Nobilling
    vals = append(vals, nobil)

    if nobil == row.billing {
        continue
    }

    i++
}

我只想从数组中存储不同的值

最佳答案

我想您可能正在寻找反射Reflection ...我说“思考”,因为您对问题的措辞令人困惑。像这样吗

res := []interface{}{
    1,
    "row2",
    struct { str string } { str: "what the heck???" },
}
// one way of reflecting
for i, v := range res {
    if r, ok := v.(int); ok {
        fmt.Printf("%d: You have an int: %d\n", i, r)
    } else if r, ok := v.(string); ok {
        fmt.Printf("%d: You have a string: %q\n", i, r)
    } else {
        fmt.Printf("%d: Have no idea what this type is: %T\n", i, v)
    }
}
// a cleaner way of reflecting (in my opinion)
for i, v := range res {
    switch r := v.(type) {
    case int:
        fmt.Printf("%d: You have an int: %d\n", i, r)
    case string:
        fmt.Printf("%d: You have a string: %q\n", i, r)
    default:
        fmt.Printf("%d: Have no idea what this type is: %T\n", i, v)
    }
}

在操场上检查它:https://play.golang.org/p/ca7umhCBXt3

或在“旅途中”中:https://tour.golang.org/methods/16

07-26 09:29