Click here to Skip to main content
15,032,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
<b< b="">I cannot import the json content in the example into the tables with the standard displayed codes. How do I convert nested data to datatable?

What I have tried:

public class Location
{
public double lat { get; set; }
public double lon { get; set; }
}

public class DeliveryAddress
{
public string id { get; set; }
public string address { get; set; }
public string aptNo { get; set; }
public string floor { get; set; }
public string doorNo { get; set; }
public string city { get; set; }
public string district { get; set; }
public string description { get; set; }
}

public class Client
{
public string id { get; set; }
public string name { get; set; }
public Location location { get; set; }
public string clientPhoneNumber { get; set; }
public string contactPhoneNumber { get; set; }
public DeliveryAddress deliveryAddress { get; set; }
}

public class Courier
{
public string id { get; set; }
public int status { get; set; }
public string name { get; set; }
public Location location { get; set; }
}

public class Name
{
public string tr { get; set; }
public string en { get; set; }
}

public class Option
{
public string option { get; set; }
public Name name { get; set; }
public double price { get; set; }
}

public class OptionCategory
{
public string optionCategory { get; set; }
public Name Name { get; set; }
public IList options { get; set; }
}

public class Title
{
public string tr { get; set; }
public string en { get; set; }
}

public class Options
{
public IList tr { get; set; }
public IList en { get; set; }
}

public class DisplayInfo
{
public Title title { get; set; }
public Options options { get; set; }
}

public class Product
{
public string id { get; set; }
public string imageURL { get; set; }
public string wideImageURL { get; set; }
public int count { get; set; }
public string product { get; set; }
public string chainProduct { get; set; }
public Name name { get; set; }
public double price { get; set; }
public double optionPrice { get; set; }
public double priceWithOption { get; set; }
public double totalPrice { get; set; }
public double totalOptionPrice { get; set; }
public double totalPriceWithOption { get; set; }
public OptionCategory optionCategories { get; set; }
public DisplayInfo displayInfo { get; set; }
public string note { get; set; }
}

public class Restaurant
{
public string id { get; set; }
}

public class PaymentMethodText
{
public string en { get; set; }
public string tr { get; set; }
}
public class Kolonlar
{
public string id { get; set; }
public int status { get; set; }
public bool isScheduled { get; set; }
public string confirmationId { get; set; }
public Client client { get; set; }
public Courier courier { get; set; }
public IList product { get; set; }
public string clientNote { get; set; }
public double totalPrice { get; set; }
public DateTime checkoutDate { get; set; }
public int deliveryType { get; set; }
public bool doNotKnock { get; set; }
public bool isEcoFriendly { get; set; }
public Restaurant restaurant { get; set; }
public int paymentMethod { get; set; }
public PaymentMethodText paymentMethodText { get; set; }
}
Posted
Updated 22-May-21 23:58pm
v2

1 solution

You can use any online JSON to C# class converter for the same:
C#
// Usage
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
 
public class Location
{
    public double lat { get; set; }
    public double lon { get; set; }
}

public class DeliveryAddress
{
    public string id { get; set; }
    public string address { get; set; }
    public string aptNo { get; set; }
    public string floor { get; set; }
    public string doorNo { get; set; }
    public string city { get; set; }
    public string district { get; set; }
    public string description { get; set; }
}

public class Client
{
    public string id { get; set; }
    public string name { get; set; }
    public Location location { get; set; }
    public string clientPhoneNumber { get; set; }
    public string contactPhoneNumber { get; set; }
    public DeliveryAddress deliveryAddress { get; set; }
}

public class Courier
{
    public string id { get; set; }
    public int status { get; set; }
    public string name { get; set; }
    public Location location { get; set; }
}

public class Name
{
    public string tr { get; set; }
    public string en { get; set; }
}

public class Option
{
    public string option { get; set; }
    public Name name { get; set; }
    public int price { get; set; }
    public List<string> tr { get; set; }
    public List<string> en { get; set; }
}

public class OptionCategory
{
    public string optionCategory { get; set; }
    public Name name { get; set; }
    public List<Option> options { get; set; }
}

public class Title
{
    public string tr { get; set; }
    public string en { get; set; }
}

public class DisplayInfo
{
    public Title title { get; set; }
    public Options options { get; set; }
}

public class Product
{
    public string id { get; set; }
    public string imageURL { get; set; }
    public string wideImageURL { get; set; }
    public int count { get; set; }
    public string product { get; set; }
    public string chainProduct { get; set; }
    public Name name { get; set; }
    public int price { get; set; }
    public int optionPrice { get; set; }
    public int priceWithOption { get; set; }
    public int totalPrice { get; set; }
    public int totalOptionPrice { get; set; }
    public int totalPriceWithOption { get; set; }
    public List<OptionCategory> optionCategories { get; set; }
    public DisplayInfo displayInfo { get; set; }
    public string note { get; set; }
}

public class Restaurant
{
    public string id { get; set; }
}

public class PaymentMethodText
{
    public string en { get; set; }
    public string tr { get; set; }
}

public class Root
{
    public string id { get; set; }
    public int status { get; set; }
    public bool isScheduled { get; set; }
    public string confirmationId { get; set; }
    public Client client { get; set; }
    public Courier courier { get; set; }
    public List<Product> products { get; set; }
    public string clientNote { get; set; }
    public int totalPrice { get; set; }
    public DateTime checkoutDate { get; set; }
    public int deliveryType { get; set; }
    public bool doNotKnock { get; set; }
    public bool isEcoFriendly { get; set; }
    public Restaurant restaurant { get; set; }
    public int paymentMethod { get; set; }
    public PaymentMethodText paymentMethodText { get; set; }
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900