douqiao4450
2014-01-16 01:27无法将字符串解组为int64类型的Go值
I have struct
type tySurvey struct {
Id int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
I do json.Marshal
write JSON bytes in HTML page. jQuery modifies name
field in object and encodes object using jQueries JSON.stringify
and jQuery posts string to Go handler.
id
field encoded as string.
Sent: {"id":1}
Received: {"id":"1"}
Problem is that json.Unmarshal
fails to unmarshal that JSON because id
is not integer anymore.
json: cannot unmarshal string into Go value of type int64
What is best way to handle such data? I do not wish to manually convert every field. I wish to write compact, bug free code.
Quotes is not too bad. JavaScript does not work well with int64.
I would like to learn the easy way to unmarshal json with string values in int64 values.
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- 在Golang中将uint64转换为字符串
- string
- strconv
- type-conversion
- 5个回答
- Golang将json值从int转换为字符串
- json
- interface
- 1个回答
- Golang将字符串转换为int64
- string
- int64
- 2个回答
- json:无法将字符串解组为[] main.KVU类型的Go值
- json
- struct
- 1个回答
- json:无法将数组解组为main类型的Go值
- json
- 2个回答
换一换