How can I connvert a JSON object to a custom C# object?

This one depends on the Newtonsoft NuGet package, which is faster than the default serializer.

if we have a class then we can use the below code:

Mycustomclassname oMycustomclassname = Newtonsoft.Json.JsonConvert.DeserializeObject<Mycustomclassname>(jsonString);

if no class then use dynamic:

var oMycustomclassname = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(jsonString);

Leave a Comment