0

I am trying to read the result of this Post request...

public class Stuff
{
    string token { get; set; }
    string type { get; set; }
    long expires_in { get; set; }
}        

var request = new RestRequest(Method.POST);
IRestResponse response = client.Execute(request);
Stuff result = JsonConvert.DeserializeObject<Stuff>(response.Content);

I'm getting the correct response but I need to populate the object with the content.

response.Content is three values that match the names I'm using.

But result ends up null for those three values (0 for the long). Shouldn't it match up and populate the object?

zhulien
  • 5,145
  • 3
  • 22
  • 36
John
  • 371
  • 2
  • 4
  • 16

1 Answers1

1

The solution here is to make the properties in the class public.

public class Stuff
{
    public string token { get; set; }
    public string type { get; set; }
    public long expires_in { get; set; }
}   

If however you need/want a private setter you can use the JsonProperty attribute.

[JsonProperty]
public string token { get; private set; }

More information on this can be found at this question

Ryan Thomas
  • 1,724
  • 2
  • 14
  • 27