You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I read the response quirks on the readme but have so far been unable to get a struct populated using the response.JSON() method.
I'm using the latest version of grequests with Go 1.11. Here is the chunk of code in question:
resp, _ := session.Post(loginapi, ro)
fmt.Println(resp.Bytes())
fmt.Println(resp.String()) // S1
fmt.Println(resp.StatusCode)
var r = new(APIResponse)
fmt.Println(resp.JSON(&r))
fmt.Println(resp.String()) // S2
In this scenario, S1 will print the response string and S2 will be empty. If I remove the resp.JSON() line everything works fine. Even if I try to call resp.JSON() first to populate before any other response method calls, the struct comes back nil.
The text was updated successfully, but these errors were encountered:
Please note that resp.JSON does return an error instead of your filled data struct. That is the reason, why you need to provide a pointer to it. So if resp.JSON returns nil no error occurred while unmarshaling the json string.
I read the response quirks on the readme but have so far been unable to get a struct populated using the response.JSON() method.
I'm using the latest version of grequests with Go 1.11. Here is the chunk of code in question:
In this scenario, S1 will print the response string and S2 will be empty. If I remove the
resp.JSON()
line everything works fine. Even if I try to call resp.JSON() first to populate before any other response method calls, the struct comes back nil.The text was updated successfully, but these errors were encountered: