gpt4 book ai didi

json - 小写的 Golang JSON 结构不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 03:06:19 27 4
gpt4 key购买 nike

我有一个结构:

type Credentials struct {
Username string `json:"username"`
Password string `json:"password"`
ApplicationId string `json:"application_id"`
ApplicationKey string `json:"application_key"`
}

而且我已将我的字段标记为小写。

但是,每当我包含应用程序标签时,这些字段都会变为空,即在我的 POST 请求中我得到

{ application_id: '',
application_key: '',
password: 'myPassword',
username: 'myUsername'
}

但是如果我删除其中一个标签(因此删除 ApplicatinonIdApplicationKey 标签),那么该字段会显示

这是我设置结构的方式:

func getCredentials() Credentials {
raw, err := ioutil.ReadFile(os.Getenv("BASE_PATH") + FILE_Credentials)
if err != nil {
log.Warn("Could not read credentials file: %s", err.Error())
os.Exit(1)
}

var credentials Credentials
json.Unmarshal(raw, &credentials)
return credentials
}

我的凭证 json 文件是:

{
"Username": "myUsername",
"Password": "myPassowrd",
"ApplicationId": "someID",
"ApplicationKey": "someString"
}

然后,我发布我的数据:

credentials := getCredentials()
url := GetLoginURL()

resp, body, requestErr := gorequest.New().
Post(url).
Send(credentials).
End()

但是在服务器上,我得到的 application_idapplication_key 都是空字符串。但是如果我删除相应的标签,那么该字段就会被发布

最佳答案

看起来您的凭证文件有误(它需要使用键 application_id 和 application_key - Go 足够聪明,可以计算出大小写,但不能计算下划线):

{
"Username": "myUsername",
"Password": "myPassowrd",
"application_id": "someID",
"application_key": "someString"
}

关于json - 小写的 Golang JSON 结构不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36224779/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com