How do I unmarshal a string value from a JSON document into a variable of type int?
问题 My struct: type User struct { FirstName string `json:"firstname, omitempty" validate:"required"` LastName string `json:"lastname, omitempty" validate:"required"` NumberofDays int `json:"numberofdays, string" validate:"min=0,max=100"` } Value for NumberofDays is passed as string from the server but I want to check if it is within range and store as int. Ex: user := &User{"Michael","Msk","3"} I'm getting 'cannot unmarshal string into Go value of type int'. I'm not sure how to typecast to int