In C# side I have DataTable AccountRecords – in AccountRecords there are 2 columns with multiple rows.
For example :
AccountRecords :-
OldNumber NewNumber
726536 98237498
123756 12786877
716666 65693466
Using C# How do I add the AccountRecords information to InvalidPolicies section as mentioned below :-
{
"InvalidPolicies": [
{
" OldNumber": "726536",
" NewNumber": "98237498"
},
{
" OldNumber": "123756",
" NewNumber": "12786877"
},
{
" OldNumber": "716666",
" NewNumber": "65693466"
}
],
"ReceivedCount": 3,
"SuccessCount": 2,
"FailedCount": 1,
"Notices": [],
"Actions": {}
}

Tahir AnsariRank #366 · 6.8K reputationPosted Aug 10, 2023, 11:25 PM EDT
using System; using System.Collections.Generic; using Newtonsoft.Json; public class InvalidPolicy { public string OldNumber { get; set; } public string NewNumber { get; set; } } class Program { static void Main() { // Create your DataTable (assuming you already have it) DataTable accountRecords = new DataTable(); // ... Add data to the DataTable ... List invalidPolicies = new List(); foreach (DataRow row in accountRecords.Rows) { invalidPolicies.Add(new InvalidPolicy { OldNumber = row["OldNumber"].ToString(), NewNumber = row["NewNumber"].ToString() }); } var result = new { InvalidPolicies = invalidPolicies, ReceivedCount = invalidPolicies.Count, SuccessCount = 0, // Set the actual success count FailedCount = 0, // Set the actual failed count Notices = new List(), // Empty notices for now Actions = new Dictionary() // Empty actions for now }; string jsonResult = JsonConvert.SerializeObject(result, Formatting.Indented); Console.WriteLine(jsonResult); } }Kumar AURank #3,821 · 387 reputationPosted Aug 11, 2023, 10:07 AM EDT
Thank you Tahir for your response it worked