Generated Json2CSharp --- Now What


  • I am coding a console app that gets a JSON response from an API.  I have everything coded (all 5 lines) but am not sure how to deserialize the JSON response.  This is what I have thus far - now how can I use the syntax generated from Json2Csharp to get a usable deserialized output?

            static void Main(string[] args)
                string num= "10";
                var url = "https/?acnm=" + num;
                var syncClient = new WebClient();
                syncClient.Headers.Set("Key", "XXXXXXXXXXXX");
                syncClient.Headers.Set("user", "user");
                syncClient.Headers.Set("pass", "pwd");
                var content = syncClient.DownloadString(url);

    Thursday, April 6, 2017 1:40 PM


  • Most people use JSON.NET to handle this. You can add the NuGet package for it. You can post questions related to using it on their site but for the most part it is one line of code once you've defined the .NET type to store the JSON object in.

    There are other alternatives as well including the DataContractSerializer.

    Michael Taylor

    • Marked as answer by IndigoMontoya Thursday, April 6, 2017 5:29 PM
    Thursday, April 6, 2017 3:40 PM