Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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);
Posted
Updated 9-Nov-22 3:01am
Comments
OriginalGriff 9-Nov-22 5:12am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

I am not sure what you are trying to do or if you are using Newtonsoft.Json or System.Text.Json, but here are two articles written to answer questions like these:
* Working with Newtonsoft.Json in C# & VB[^]
* Working with System.Text.Json in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900