我的测试处理程序代码在这里:
func defineHandler(w http.ResponseWriter, r *http.Request) {
a := strconv.ParseInt(r.FormValue("aRows")[0:], 10, 64);
b := r.FormValue("aRows");
fmt.Fprintf(w, "aRows is: %s", b);
}
编译过程中返回的错误如下: “单值上下文中的多值 strconv.ParseInt()”
我认为这与 FormValue 中的信息格式有关,我只是不知道如何缓解这种情况。
最佳答案
意思是strconv.ParseInt
有多个返回值(int 和一个错误),因此您需要执行以下操作:
a, err := strconv.ParseInt(r.FormValue("aRows")[0:], 10, 64);
if err != nil {
// handle the error in some way
}
关于html - 如何在 Golang 中将 HTML 表单值转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19239890/