0

Environment: VS2015 Console app

How do I convert the response to my entity object?

Article was found here, under WebClient Class.

Also was wondering what JArray is? I found something in Newtonsoft.JSON and MS MVC.

var client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
var response = client.DownloadString("https://api.github.com/repos/restsharp/restsharp/releases");
var releases = JArray.Parse(response);
Rod
  • 14,529
  • 31
  • 118
  • 230
  • 1
    From the article: `We are going to utilize the help of the Json.NET library to deserialize the response we get`. It is probably a method they made for deresializing. – VDWWD Mar 05 '19 at 21:55
  • This question has been asked dozens of times on SO. Search google for `site:stackoverflow.com c# deserialize json model` –  Mar 05 '19 at 21:56
  • 2
    Possible duplicate of [How to deserialize complex object of JSON](https://stackoverflow.com/questions/16339167/)? – Dour High Arch Mar 05 '19 at 21:58

1 Answers1

1

Simply use Newtonsoft.Json NuGet package this way.

YourEntity entity = JsonConvert.DeserializeObject<YourEntity>(response);
ALFA
  • 1,726
  • 1
  • 10
  • 19