Cannot unmarshal string into Go value of type int64

删除回忆录丶 提交于 2019-12-02 18:52:19

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.

KaungMyatChanThar
Sent: {"id":1} Received: {"id":"1"}

Let's fix this.

Your case is -> http post 'localhost:8080/users/blahblah' id=1

Change it to -> http post 'localhost:8080/users/blahblah' id:=1

No need to do "json:id,string" thing, Just "json:id" is enough. Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!