json:无法将数字 5088060241 解组为 int 类型的结构
时间:2024-04-14
浏览:279
作者:佚名
小伙伴们有没有觉得学习Golang很有意思?有意思就对了!今天就给大家带来《json:无法将数字 5088060241 解组为 int 类型的结构》,以下内容将会涉及到,若是在学习中对其中部分知识点有疑问,或许看了本文就能帮到你!
问题内容
我正在使用 ovh 提供程序开发 terraform 项目,创建记录时,提供程序无法获取记录的 id 并触发此错误:
无法将数字 5088060240 解组到 int 类型的 go 结构字段 ovhdomainzonerecord.id
我在 github 存储库上提出了一个问题,但仍在等待答案。 我想自己纠正这个问题,但我不是 go 开发者,我找不到任何相关错误。
ovhdomainzonerecord 的结构:
type OvhDomainZoneRecord struct {
Id int `json:"id,omitempty"`
Zone string `json:"zone,omitempty"`
Target string `json:"target"`
Ttl int `json:"ttl,omitempty"`
FieldType string `json:"fieldType"`
SubDomain string `json:"subDomain,omitempty"`
}
相关文件: https://github.com/terraform-providers/terraform-provider-ovh/blob/master/ovh/resource_ovh_domain_zone_record.go
解决方案
int 的大小为 32 位或 64 位,具体取决于您编译和运行的目标体系结构。您的输入 5088060240 大于 32 位整数的最大值(即 2147483647),因此如果您的 int 是 32 位,则会收到此错误。
最简单的修复方法是使用 int64。请参阅此示例:
var i int32
fmt.println(json.unmarshal([]byte("5088060240"), &i))
var j int64
fmt.println(json.unmarshal([]byte("5088060240"), &j))
输出(在 Go Playground 上尝试):
json: cannot unmarshal number 5088060240 into Go value of type int32 <nil>
以上就是《json:无法将数字 5088060241 解组为 int 类型的结构》的详细内容,更多关于的资料请关注golang学习网公众号!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.20
11.20
11.20
11.20
热门专题
