Get JSON response using RestSharp

后端 未结 4 1454
长发绾君心
长发绾君心 2021-01-08 00:40

I\'m new to C# and I\'m trying to get the JSON response from a REST request using RestSharp; The request I want to execute is the following one : \"http://myurl.com/ap

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-08 00:51

    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(response);
    }
    

提交回复
热议问题