Search code examples
c#restsharp

Sending Restsharp reponse to a class


I'm trying to send the content of this API response into a custom response class. This produces a parsing error. Is there an additional conversion needed before the RestSharp response works with Newtonsoft? The class has three strings which are meant to grab the three members of the JSON with the same name.

IRestResponse response = client.Execute(request);

<CLASSNAME> content = JsonConvert.DeserializeObject<CLASSNAME>(response.ToString()); 

The parsing error is "'Unexpected character encountered while parsing value: R. Path '', line 0, position 0.'" My class is as follows:

public class Response
{

    public string name { get; set; }

    public string msg { get; set; }

    public string code { get; set; }

}

The JSON is as follows:

{
name:
msg:
code:
...bunch of other stuff...
}

Solution

  • Oh I found it! It has to be Response.Content that is deserialized. That's where the JSON is.