I want to set the Json request embedded with data tag in asp.net with c#.
After serialization,json Request
{
"RemittanceData": [
{
"Information": "TEST501"
}
],
"PaymentOrderProductId": "AHBDDA501",
"DebitAccountId": "018061058118",
"DebitCurrency": "AED",
"DebitValueDate": "20221109",
"CreditAccountId": "028676488149",
"PaymentCurrencyId": "AED",
"Amount": 10000,
"EndToEndReference": "049500130811290W20221109132539460"
Json Request Required
{
"Data": {
"RemittanceData": [
{
"Information": ""
}
],
"PaymentOrderProductId": "AHBDDA501",
"DebitAccountId": "30003198541",
"DebitCurrency": "AED",
"DebitValueDate": "20220307",
"CreditAccountId": "30000008547",
"PaymentCurrencyId": "AED",
"Amount": 1,
"EndToEndReference": "TESTDDA501"
}
}
What I have tried:
Code as below:
Class set for serialization
public class Data_501_Transact_Posting
{
public List<RemittanceDatum> RemittanceData { get; set; }
public string PaymentOrderProductId { get; set; }
public string DebitAccountId { get; set; }
public string DebitCurrency { get; set; }
public string DebitValueDate { get; set; }
public string CreditAccountId { get; set; }
public string PaymentCurrencyId { get; set; }
public decimal Amount { get; set; }
public string EndToEndReference { get; set; }
}
public class RemittanceDatum_501_Posting
{
public string Information { get; set; }
}
public class Root7
{
public Data_501_Transact_Posting Data { get; set; }
}
Data_501_Transact_Posting objDataRequest = new Data_501_Transact_Posting();
objDataRequest.PaymentOrderProductId = Convert.ToString(ds.Tables[0].Rows[i]["PaymentOrderProductId"]);
objDataRequest.DebitAccountId = Convert.ToString(ds.Tables[0].Rows[i]["DebitAccountId"]);
objDataRequest.DebitCurrency = Convert.ToString(ds.Tables[0].Rows[i]["DebitCurrency"]);
DateTime dtDebitValueDate = Convert.ToDateTime(ds.Tables[0].Rows[i]["DebitValueDate"]);
objDataRequest.DebitValueDate = dtDebitValueDate.ToString("yyyyMMdd");
objDataRequest.CreditAccountId = Convert.ToString(ds.Tables[0].Rows[i]["CreditAccountId"]);
objDataRequest.PaymentCurrencyId = Convert.ToString(ds.Tables[0].Rows[i]["PaymentCurrencyId"]);
objDataRequest.Amount = Convert.ToInt32(ds.Tables[0].Rows[i]["Amount"]);
objDataRequest.EndToEndReference = Convert.ToString(ds.Tables[0].Rows[i]["EndToEndReference"]);
List<RemittanceDatum> Listdata = new List<RemittanceDatum>();
for (int j = 0; j < ds.Tables[1].Rows.Count; j++)
{
if (Convert.ToString(ds.Tables[0].Rows[i]["DD501TransactPostingId"]) == Convert.ToString(ds.Tables[1].Rows[j]["DD501TransactPostingId"]))
{
Listdata.Add(new RemittanceDatum
{
Information = Convert.ToString(ds.Tables[1].Rows[j]["Information"])
});
}
}
IN_501_TRANSACT_POSTING_DETAILS obj501TransactDtls = new IN_501_TRANSACT_POSTING_DETAILS();
obj501TransactDtls.RemittanceData = Listdata;
objDataRequest.RemittanceData = obj501TransactDtls.RemittanceData;
string jsonRequest = JsonConvert.SerializeObject(objDataRequest);