Cannot unmarshal string into Go value of type int64

后端 未结 2 1103
无人共我
无人共我 2021-02-01 13:29

I have struct

type tySurvey struct {
    Id     int64            `json:\"id,omitempty\"`
    Name   string           `json:\"name,omitempty\"`
}
<
2条回答
  •  独厮守ぢ
    2021-02-01 14:20

    This is handled by adding ,string to your tag as follows:

    type tySurvey struct {
       Id   int64  `json:"id,string,omitempty"`
       Name string `json:"name,omitempty"`
    }
    

    This can be found about halfway through the documentation for Marshal.

    Please note that you cannot decode the empty string by specifying omitempty as it is only used when encoding.

提交回复
热议问题