package main

import (
"fmt"
"net/http"
"reflect"
"strings"

"github.com/gin-gonic/gin"
)

func main() {
r := gin.Default()
r.GET("queryArr", queryArray)
r.Run()
}

func queryArray(c *gin.Context) {
ids := c.QueryArray("ids")
// fmt.Println("第一种方式:", ids.(type)) //i.(type)只能在switch中使用
fmt.Println("ids", ids)
fmt.Println("接收到的参数类型:", reflect.TypeOf(ids))
for k, v := range ids {
fmt.Printf("%d ==> %v \n", k, reflect.TypeOf(v))
for i, b := range strings.Split(v, ",") {
// %c按照字符输出,而不是字符对应的数字值
// fmt.Printf("%c \n", b)
fmt.Printf("%d==>%v \n", i, b)
}
}

c.JSON(http.StatusOK, gin.H{
"ids_": ids,
})
}

go gin框架:QueryArray接收ids请求参数_json

go gin框架:QueryArray接收ids请求参数_golang_02