Ich habe eine Struktur:Golang JSON Struktur zu Klein funktioniert nicht
type Credentials struct {
Username string `json:"username"`
Password string `json:"password"`
ApplicationId string `json:"application_id"`
ApplicationKey string `json:"application_key"`
}
Und ich habe meine Felder markiert sie in Kleinbuchstaben.
Jedes Mal, wenn ich die Anwendungs-Tags enthalten, werden diese Felder null, das heißt auf meiner POST-Anfrage ich
{ application_id: '',
application_key: '',
password: 'myPassword',
username: 'myUsername'
}
bekommen, aber wenn ich entweder den Tags entfernen (so ApplicatinonId
oder ApplicationKey
Tag entfernen), dann das Feld tut zeigen
Hier ist, wie ich meine Struktur gesetzt:
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
}
My Credential json
Datei ist:
{
"Username": "myUsername",
"Password": "myPassowrd",
"ApplicationId": "someID",
"ApplicationKey": "someString"
}
Dann poste ich meine Daten mit:
credentials := getCredentials()
url := GetLoginURL()
resp, body, requestErr := gorequest.New().
Post(url).
Send(credentials).
End()
Aber auf dem Server, bekomme ich sowohl application_id
und application_key
als leere Zeichenfolge. Aber wenn ich das entsprechende Tag entferne, dann wird dieses Feld gepostet
Bitte zeigen Sie ein minimales Beispiel an, um das Problem zu reproduzieren – JimB
@JimB, Ich habe gerade meine Frage – Kousha
aktualisiert Ihre Datei hat nicht die Schlüssel: 'application_id' und' application_key' – JimB