json - json:无法将数字 5088060241 解组为 int 类型的结构
问题描述
我正在使用 OVH 提供程序处理 Terraform 项目,创建记录时,提供程序无法获取记录的 ID 并触发此错误:
cannot unmarshal number 5088060240 into Go struct field OvhDomainZoneRecord.id of type int
我在 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"`
}
解决方案
大小为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>
推荐阅读
- javascript - 使用邮递员招摇 api 的请求没有正文
- google-apps-script - 表格没有反应
- rest - 没有正文的 Activemq REST=
- spring - 计划任务执行器意外崩溃
- php - 使用 PHP 将多个查询结果集合并到一个数组中
- python - 如何在 tkinter Python 3.7 中为组合框下拉菜单绑定按键事件
- vim - VI 显示使用 git bash split 拆分大文本文件后的控制字符
- javascript - 如何限制 100 个 Chartjs 中的样本
- spring - Spring在创建父对象时如何添加子实体
- sql - 运行排除重复行的 JOIN 语句