Hi
How to create a class for below like Json Data
var body = @"{" + "\n" +
@" ""order_number"": ""#001""," + "\n" +
@" ""shipping_charges"": 40," + "\n" +
@" ""discount"": 100," + "\n" +
@" ""cod_charges"": 30," + "\n" +
@" ""payment_type"": ""cod""," + "\n" +
@" ""order_amount"": 1000," + "\n" +
@" ""package_weight"": 300," + "\n" +
@" ""package_length"": 10," + "\n" +
@" ""package_breadth"": 10," + "\n" +
@" ""package_height"": 10," + "\n" +
@" ""consignee"": {" + "\n" +
@" ""name"": ""Customer Name""," + "\n" +
@" ""address"": ""190, ABC Road""," + "\n" +
@" ""address_2"": ""Near Bus Stand""," + "\n" +
@" ""city"": ""Mumbai""," + "\n" +
@" ""state"": ""Maharastra""," + "\n" +
@" ""pincode"": ""400001""," + "\n" +
@" ""phone"": ""9999999999""" + "\n" +
@" }," + "\n" +
@" ""pickup"": {" + "\n" +
@" ""warehouse_name"": ""warehouse 1""," + "\n" +
@" ""name"" : ""Vikalp Sharma""," + "\n" +
@" ""address"": ""140, MG Road""," + "\n" +
@" ""address_2"": ""Near metro station""," + "\n" +
@" ""city"": ""Gurgaon""," + "\n" +
@" ""state"": ""Haryana""," + "\n" +
@" ""pincode"": ""122001""," + "\n" +
@" ""phone"": ""9999999999""" + "\n" +
@" }," + "\n" +
@" ""order_items"": [" + "\n" +
@" {" + "\n" +
@" ""name"": ""product 1""," + "\n" +
@" ""qty"": ""18""," + "\n" +
@" ""price"": ""100""," + "\n" +
@" ""sku"": ""sku001""" + "\n" +
@" }" + "\n" +
@" ]" + "\n" +
@"}";
Thanks
Uday DodiyaPosted Dec 21, 2022, 10:46 AM
Your file name should be ModelClass.cs
Aravind GovindarajPosted Dec 21, 2022, 10:31 AM
you can do it manually or quick way using the below link
https://json2csharp.com/
JSON :
"order_number": "#001",
"shipping_charges": 40,
"discount": 100,
"cod_charges": 30,
"payment_type": "cod",
"order_amount": 1000,
"package_weight": 300,
"package_length": 10,
"package_breadth": 10,
"package_height": 10,
"consignee": {
"name": "Customer Name",
"address": "190, ABC Road",
"address_2": "Near Bus Stand",
"city": "Mumbai",
"state": "Maharastra",
"pincode": "400001",
"phone": "9999999999"
},
"pickup": {
"warehouse_name": "warehouse 1",
"name" : "Vikalp Sharma",
"address": "140, MG Road",
"address_2": "Near metro station",
"city": "Gurgaon",
"state": "Haryana",
"pincode": "122001",
"phone": "9999999999"
},
"order_items": [
{
"name": "product 1",
"qty": "18",
"price": "100",
"sku": "sku001"
}
]
Class
// Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse);
public class Consignee
{
public string name { get; set; }
public string address { get; set; }
public string address_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string pincode { get; set; }
public string phone { get; set; }
}
public class OrderItem
{
public string name { get; set; }
public string qty { get; set; }
public string price { get; set; }
public string sku { get; set; }
}
public class Pickup
{
public string warehouse_name { get; set; }
public string name { get; set; }
public string address { get; set; }
public string address_2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string pincode { get; set; }
public string phone { get; set; }
}
public class Root order_items { get; set; }
{
public string order_number { get; set; }
public int shipping_charges { get; set; }
public int discount { get; set; }
public int cod_charges { get; set; }
public string payment_type { get; set; }
public int order_amount { get; set; }
public int package_weight { get; set; }
public int package_length { get; set; }
public int package_breadth { get; set; }
public int package_height { get; set; }
public Consignee consignee { get; set; }
public Pickup pickup { get; set; }
public List
}