How to convert JSON text into objects using C#

  1. To create a class off a json string, copy the string.

  2. In Visual Studio, in the menu at the top, click Edit > Paste special > Paste Json as classes.

  3. Install Newtonsoft.Json via Nuget

  4. Paste the following code into your project, “jsonString” being the variable you want to deserialize :

    Rootobject r = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(jsonString);

  5. Don’t forget to rename Rootobject to be more descriptive eg ILoveTheSmellOfNapalmInTheMorning-that was a joke

Leave a Comment