Hi, @MyLadys-4900 ,
I tried both System.Text.Json
and Newtonsoft.Json
. And it works as expect. It might be related with the format of your dtls. You could try to deserialize by Newtonsoft.Json
.
Newtonsoft.Json
is flexible by default while System.Text.Json
is strict.
Below are codes.
var dtls = "[{\"TransactionId\":1015,\"CName\":\"Don\",\"TDate\":\"May 9 2020 4:54PM\",\"BDate\":\"May 9 2020 4:54PM\",\"Initials\":\"JMC\",\"IsBilled\":false,\"IsPaid\":false,\"SvcLevel\":\"R1\"}," +
"{\"TransactionId\":988,\"CName\":\"Don\",\"TDate\":\"Jan 23 2020 3:13PM\",\"BDate\":\"Mar 10 2020 11:17AM\",\"Initials\":\"JMC\",\"IsBilled\":false,\"IsPaid\":false,\"SvcLevel\":\"R1\"}," +
"{\"TransactionId\":974,\"CName\":\"Don\",\"TDate\":\"Jan 22 2020 2:36PM\",\"BDate\":\"Jan 22 2020 2:36PM\",\"Initials\":\"JMC\",\"IsBilled\":false,\"IsPaid\":false,\"SvcLevel\":\"R1\"}]";
List<RecordDetail> details = System.Text.Json.JsonSerializer.Deserialize<List<RecordDetail>>(dtls);
foreach (RecordDetail record in details)
{
Console.WriteLine("TransactionId: " + record.TransactionId);
Console.WriteLine("CName: " + record.CName);
Console.WriteLine("TDate: " + record.TDate);
Console.WriteLine("BDate: " + record.BDate);
Console.WriteLine("Initials: " + record.Initials);
Console.WriteLine("IsBilled: " + record.IsBilled);
Console.WriteLine("IsPaid: " + record.IsPaid);
Console.WriteLine("SvcLevel: " + record.SvcLevel);
Console.WriteLine("");
}
List<RecordDetail> ndetails = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RecordDetail>>(dtls);
foreach (RecordDetail record in ndetails)
{
Console.WriteLine("TransactionId: " + record.TransactionId);
Console.WriteLine("CName: " + record.CName);
Console.WriteLine("TDate: " + record.TDate);
Console.WriteLine("BDate: " + record.BDate);
Console.WriteLine("Initials: " + record.Initials);
Console.WriteLine("IsBilled: " + record.IsBilled);
Console.WriteLine("IsPaid: " + record.IsPaid);
Console.WriteLine("SvcLevel: " + record.SvcLevel);
Console.WriteLine("");
}
}
Screenshot
------
If the answer doesn’t solve your issue, please provide more details of error that will help us track down what’s happening.
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Michael Wang