如何在C#点中将JSON字符串反序列化为对象列表

我正在使用以下JSON字符串

{

"transactions":

[

{

"paymentcharge":"0.0",

"amount":352,

"id":13418,

"shippingcharge":35,

"shippingtype":2,

"status":2,

"paymenttype":1,

"date":"2012-10-06 16:15:28.0"

},

{

"paymentcharge":"0.0",

"amount":42455,

"id":16305,

"shippingcharge":0,

"shippingtype":2,

"status":2,

"paymenttype":2,

"date":"2012-11-30 09:29:29.0"

},

{

"paymentcharge":"1.0",

"amount":42456,

"id":16305,

"shippingcharge":0,

"shippingtype":2,

"status":2,

"paymenttype":2,

"date":"2012-11-30 09:29:29.0"

}

],

"count":3

}


我有一个如下的类结构,用于解析和感受json数据

class clsSalesTran

{

public double paymentcharge { get; set; }

public double amount { get; set; }

public long id { get; set; }

public int shippingcharge { get; set; }

public int shippingtype { get; set; }

public int status { get; set; }

public int paymenttype { get; set; }

public DateTime date { get; set; }

}


如何将上述JSON字符串反序列化为List?

我正在使用 Newtonsoft.Json 进行反序列化。

回答:

首先创建另一个类:

public class SalesTransactions

{

public List<clsSalesTran> transactions {get;set;}

public int count{get;set;}

}

然后用

JsonConvert.DeserializeObject<SalesTransactions>(inputString)

以上是 如何在C#点中将JSON字符串反序列化为对象列表 的全部内容, 来源链接: utcz.com/qa/412642.html

回到顶部