Skip to content

Instantly share code, notes, and snippets.

@LaughingVzr
Created July 11, 2018 08:54
Show Gist options
  • Save LaughingVzr/71b86b8a55cc9769c6c88e5c46f26ec2 to your computer and use it in GitHub Desktop.
Save LaughingVzr/71b86b8a55cc9769c6c88e5c46f26ec2 to your computer and use it in GitHub Desktop.
[Golang原生json包[]interface转[]string] #golang #json
// 对参数进行断言,确定类型并获取参数
if targetParam, ok := params["a"].([]interface{}); ok {
for _, param := range targetParam {
switch v := param.(type) {
case string:
paramArr = append(paramArr, v)
case float64:
paramArr = append(paramArr, strconv.FormatFloat(v, 'f', 0, 64))
case int64:
paramArr = append(paramArr, strconv.FormatInt(v, 10))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment