How to deserialize json string to object list in c# dot
first create another class:
public class SalesTransactions
{
public List<clsSalesTran> transactions {get;set;}
public int count{get;set;}
}
Then use,
JsonConvert.DeserializeObject<SalesTransactions>(inputString)
Create a class as below
By creating the list of class 'clsSalesTran' and a variable for 'Count'
Note: JsonProperty is mandatory from your Json String
public class SalesTransactions
{
[JsonProperty("transactions")]
public List<clsSalesTran> transactions {get;set;}
public int count{get;set;}
}
Then you may use this class as below to deserialize
SalesTransactions st = JsonConvert.DeserializeObject<SalesTransactions>(inputString)
Use the Deserialized object as below
double paymentcharge = st.transactions[0].paymentcharge;
To deserialize a string to a List
of objects of type clsSalesTran
:
var myList = JsonConvert.DeserializeObject<List<clsSalesTran>>(inputString);