Cannot unmarshal string into Go value of type int64

后端 未结 2 1102
无人共我
无人共我 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:01

    use json.Number

    type tySurvey struct {
        Id     json.Number      `json:"id,omitempty"`
        Name   string           `json:"name,omitempty"`
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题