I run below javascript code.
return $.ajax({
url: "/loyalty/api/rule/new",
type: "POST",
contentType: "application/json",
data: JSON.stringify({'rule':$('form').serializeObject(),'ruleId':ruleID(),'programId':parseInt(proID)})
});
and I use below code to decode it.
decoder := json.NewDecoder(r.Body)
var rules models.NewRule
err := decoder.Decode(&rules)
but then it gives below error message.
level=error msg="json: cannot unmarshal string into Go value of type models.NewRule" api="/rule/new" code=400 tenantid=7 username=admin
can you help me to fix this?
my NewRule struct
type NewRule struct {
TenantID int `db:"tenantId"json:"tenantId"`
ProgramID commons.NullInt64 `db:"programId"json:"programId"`
RuleID commons.NullInt64 `db:"ruleId"json:"ruleId"`
Rule commons.NullString `db:"rule"json:"rule"`
}
func (p NewRule) String() string {
b, _ := json.Marshal(p)
return string(b)
}