this is my json.
<pre>{"status":200,"status_messages":"Success ","SuspendDate":null,"SubTotal":100,"Freight":0.0,"Discount":0.0,"TotalAmount":100,"CustomerCode":-1,"TableName":"TableNo2","CreatedBy":"admin","TokenNumber":"Token Number 1","MySuspendDetail":[{"RowID":1,"ProductCode":1,"RetailPrice":10,"Quantity":10,"Total":100,"TaxId":1,"ProductTax":0,"ExtraSuggestion":null,"MyModifiers":[{"ProductCode":1,"ModifierID":1,"ModifierGroupID":1,"ModifierName":"Frees","Price":0,"Quantity":10},{"ProductCode":1,"ModifierID":1,"ModifierGroupID":1,"ModifierName":"Frees","Price":0,"Quantity":10}]},{"RowID":1,"ProductCode":1,"RetailPrice":10,"Quantity":10,"Total":100,"TaxId":1,"ProductTax":0,"ExtraSuggestion":null,"MyModifiers":[{"ProductCode":1,"ModifierID":1,"ModifierGroupID":1,"ModifierName":"Frees","Price":0,"Quantity":10},{"ProductCode":1,"ModifierID":1,"ModifierGroupID":1,"ModifierName":"Frees","Price":0,"Quantity":10}]}]}
and these are c# classes
<pre> public class MySuspend
{
public long SuspendID { get; set; }
public DateTime SuspendDate { get; set; }
public double Subtotal { get; set; }
public double Freight { get; set; }
public double Discount { get; set; }
public double TotalAmount { get; set; }
public int CustomerCode { get; set; }
public string TableName { get; set; }
public string CreatedBy { get; set; }
public string TokenNumber { get; set; }
}
public class MySuspendDetail
{
public long SuspendID { get; set; }
public int RowID { get; set; }
public long ProductCode { get; set; }
public double ProductPrice { get; set; }
public int Quantity { get; set; }
public double Total { get; set; }
public int TaxId { get; set; }
public double ProductTax { get; set; }
public string ExtraSuggestion { get; set; }
List<MyModifiers> MD { get; set; }
}
public class MyModifiers
{
public long ProductCode { get; set; }
public int ModifierID { get; set; }
public int ModifierGroupID { get; set; }
public string ModifierName { get; set; }
public double Price { get; set; }
public double Quantity { get; set; }
}
public class PlacingOrder
{
public Collection<MySuspendDetail> SuspendDetailTable { get; set; }
}
public class OrderPlace
{
public long SuspendID { get; set; }
public int CustomerID { get; set; }
public string TableName { get; set; }
public string CreatedBy { get; set; }
public string TokenNumber { get; set; }
public List<MySuspendDetail> data { get; set; }
}
i want to deserialized json into these classes
i have tried the following code to deserialize
What I have tried:
i have tried the following code to deserialize json
public bool Ordering()
{
try
{
string st = "{'status':200,'status_messages':'Success ','SuspendDate':null,'SubTotal':100,'Freight':0.0,'Discount':0.0,'TotalAmount':100,'CustomerCode':-1,'TableName':'TableNo2','CreatedBy':'admin','TokenNumber':'Token Number 1','MySuspendDetail':[{'RowID':1,'ProductCode':1,'RetailPrice':10,'Quantity':10,'Total':100,'TaxId':1,'ProductTax':0,'ExtraSuggestion':null,'MyModifiers':[{'ProductCode':1,'ModifierID':1,'ModifierGroupID':1,'ModifierName':'Frees','Price':0,'Quantity':10},{'ProductCode':1,'ModifierID':1,'ModifierGroupID':1,'ModifierName':'Frees','Price':0,'Quantity':10}]},{'RowID':1,'ProductCode':1,'RetailPrice':10,'Quantity':10,'Total':100,'TaxId':1,'ProductTax':0,'ExtraSuggestion':null,'MyModifiers':[{'ProductCode':1,'ModifierID':1,'ModifierGroupID':1,'ModifierName':'Frees','Price':0,'Quantity':10},{'ProductCode':1,'ModifierID':1,'ModifierGroupID':1,'ModifierName':'Frees','Price':0,'Quantity':10}]}]}";
JavaScriptSerializer js = new JavaScriptSerializer();
OrderPlace OR = js.Deserialize<OrderPlace>(st);
MySuspend ms = new MySuspend();
ms.SuspendID = GetMaxSuspendID();
ms.SuspendDate =System.DateTime. Now;
ms.Subtotal = 0.0;
ms.CreatedBy = OR.CreatedBy;
ms.CustomerCode = OR.CustomerID;
List<MySuspendDetail> datasubitems =OR.data ;
return true;
}
catch(Exception e)
{
return false;
}
}
but get null in
datasubitems
.