How do I create a Dto in C# Asp.Net from a fairly complex Json Response

Copy the JSON and then in Visual Studio, in the menu bar go to: Edit > Paste Special > Paste JSON as Classes:

enter image description here

And it will produce the following for your JSON:

public class Rootobject {
   public Response response { get; set; }
}

public class Response {
   public Result result { get; set; }
   public string uri { get; set; }
}

public class Result {
   public Leads Leads { get; set; }
}

public class Leads {
   public Row[] row { get; set; }
}

public class Row {
   public string no { get; set; }
   public FL[] FL { get; set; }
}

public class FL {
   public string val { get; set; }
   public string content { get; set; }
}

You can also do the same with XML by choosing the Paste XML as Classes option.

Leave a Comment