我有一个奇怪的问题。我正在使用echo
包进行路由。当我解码json
时,struct
我得到了错误parsing time \"\"2019-01-02\"\" as \"\"2006-01-02T15:04:05Z07:00\"\": cannot parse \"\"\" as \"T\""
我的结构
VendorAgreement struct {
ID primitive.ObjectID `json:"id" bson:"_id"`
StartDate time.Time `json:"start_date,date" bson:"start_date"`
EndDate time.Time `json:"end_date,date" bson:"end_date"`
CommissionPercentage float32 `json:"commission_percentage" bson:"commission_percentage"`
Status int `json:"status" bson:"status"`
CreatedDate time.Time `json:"created_date" bson:"created_date"`
Media VendorAgreementMedia `json:"media" bson:"media"`
}
VendorAgreementMedia struct {
MediaId primitive.ObjectID `json:"mediaId" bson:"_id"`
FileName string `json:"file_name" bson:"file_name"`
SourcePath string `json:"source_path" bson:"source_path"`
CreatedDate time.Time `json:"created_date" bson:"created_date"`
}
我的解码步骤
var agreement VendorAgreement
err = json.NewDecoder(c.Request().Body).Decode(&agreement)
请求正文
{
"start_date":"2019-01-02",
"end_date":"2020-05-06",
"commission_percentage":10,
"media":{
"mediaId":"5cd1644cc57849f0761632b5"
}
}