简体   繁体   English

json:无法将数字 5088060241 解组为 int 类型的结构

[英]json: cannot unmarshal number 5088060241 into struct of type int

I'm working on a Terraform project using the OVH provider, when the record is created, the provider is unable to fetch the ID of the record and trigger this error : cannot unmarshal number 5088060240 into Go struct field OvhDomainZoneRecord.id of type int我正在使用 OVH 提供程序处理 Terraform 项目,当创建记录时,提供程序无法获取记录的 ID 并触发此错误: cannot unmarshal number 5088060240 into Go struct field OvhDomainZoneRecord.id of type int

I opened an issue on the github repository but still waiting for an answer.我在 github 存储库上打开了一个问题,但仍在等待答案。 I would like to correct the problem by myself but i'm not a Go developper and i canno't find any related error.我想自己解决这个问题,但我不是 Go 开发人员,我找不到任何相关的错误。

The struct of OvhDomainZoneRecord : 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"`
}

The related file : https://github.com/terraform-providers/terraform-provider-ovh/blob/master/ovh/resource_ovh_domain_zone_record.go相关文件: https : //github.com/terraform-providers/terraform-provider-ovh/blob/master/ovh/resource_ovh_domain_zone_record.go

Size of int is either 32 or 64 bit depending on the target architecture you compile to and run on. int大小为 32 位或 64 位,具体取决于您编译和运行的目标架构。 Your input 5088060240 is bigger than the max value of a 32-bit integer (which is 2147483647 ), so if your int is 32-bit, you get this error.您的输入5088060240大于 32 位整数的最大值(即2147483647 ),因此如果您的int是 32 位,则会出现此错误。

Easiest fix is to use int64 .最简单的修复方法是使用int64 See this example:看这个例子:

var i int32
fmt.Println(json.Unmarshal([]byte("5088060240"), &i))

var j int64
fmt.Println(json.Unmarshal([]byte("5088060240"), &j))

Output (try it on the Go Playground ):输出(在Go Playground上试试):

json: cannot unmarshal number 5088060240 into Go value of type int32
<nil>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 json:无法将数字解组为 Go 结构字段。字符串类型的数量 - json: cannot unmarshal number into Go struct field .Amount of type string 松露测试:ProviderError: json: cannot unmarshal number into Go struct field params.fromBlock of type string - Truffle test: ProviderError: json: cannot unmarshal number into Go struct field params.fromBlock of type string Docker:b&#39;json:无法将数字解组为Go结构字段LogConfig.Config,类型为string&#39; - Docker: b'json: cannot unmarshal number into Go struct field LogConfig.Config of type string' 无法将 JSON 字符串解组为 Go 中的结构 - Cannot Unmarshal JSON String to struct in Go golang json数组解组为struct类型 - golang json array unmarshal into type struct 如何动态选择结构类型以将 json 解组为 - How to dynamically select struct type to unmarshal json to json:无法将字符串解组为main.test_struct类型的Go值 - json: cannot unmarshal string into Go value of type main.test_struct json:无法将字符串解组为 main.CaseReport 类型的 Go struct field.result.case_report - json: cannot unmarshal string into Go struct field .result.case_report of type main.CaseReport json:无法将 object 解组为 Go 类型值 - json: cannot unmarshal object into Go value of type json解组嵌入式结构 - json unmarshal embedded struct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM