Get JSON response using RestSharp

This is old but I was just struggling with this too. This is the easiest way I found.

var client = new RestClient("http://myurl.com/api/");
var request = new RestRequest("getCatalog?token=saga001"); 
var response = client.Execute(request);

if (response.StatusCode == HttpStatusCode.OK)
{
    // Two ways to get the result:
    string rawResponse = response.Content;
    MyClass myClass = new JsonDeserializer().Deserialize<MyClass>(response);
}

Try:

var client = new RestClient("http://myurl.com/api/");

var request = new RestRequest("getCatalog?token={token}", Method.GET); 

request.AddParameter("token", "saga001", ParameterType.UrlSegment);   

// request.AddUrlSegment("token", "saga001"); 

request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

var queryResult = client.Execute(request);

Console.WriteLine(queryResult.Content);

Try as below:

var client = new RestClient("http://myurl.com/api/");

client.ClearHandlers();
var jsonDeserializer = new JsonDeserializer();
client.AddHandler("application/json", jsonDeserializer);

var request = new RestRequest("getCatalog?token=saga001"); 

var queryResult = client.Execute(request);

Console.WriteLine(queryResult);