Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to use json array using for loop in c#


My code


C#
for (int i = 0; i < child[0].roomlist.Count; i++)
            {
                var postdata = new
                {
                    fromDate = fromdate,
                    toDate = todate,
                    hotelRequest = new
                    {
                        roomList = new[]
                               {
                                           new { roomSeq = "54545", roomName = "A.c Room", tariffRequests = new[] { new { tarifSeq = "dfdf45b54", plan = "yu" } } },
                                           new { roomSeq = "5454", roomName = "Del Room", tariffRequests = new[] { new { tarifSeq = "gdgfdg;l;gfd",  plan = "Eu" } } },
                                           new { roomSeq = "5422", roomName = "Suite Room", tariffRequests = new[] { new { tarifSeq = "fdght411", plan = "Euuu" } } },
                                           new { roomSeq = "457", roomName = "Execu  Room", tariffRequests = new[] { new { tarifSeq = "gfgfgf",  plan = "tyt" } } },
                                           new { roomSeq = "222", roomName = "NonRoom", tariffRequests = new[] { new { tarifSeq = "gfgfg",  plan = "tyty" } } } }
                    },
                    datavisible = false
                };

string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(postdata);
Posted
Updated 14-Sep-15 2:42am
v2
Comments
phil.o 14-Sep-15 8:54am    
Which part of for loop usage did you not understand?
Member 10918596 14-Sep-15 9:01am    
roomList = new[]
{
new { roomSeq = "54545", roomName = "A.c Room", tariffRequests = new[] { new { tarifSeq = "dfdf45b54", plan = "yu" } } },
new { roomSeq = "5454", roomName = "Del Room", tariffRequests = new[] { new { tarifSeq = "gdgfdg;l;gfd", plan = "Eu" } } },
new { roomSeq = "5422", roomName = "Suite Room", tariffRequests = new[] { new { tarifSeq = "fdght411", plan = "Euuu" } } },
new { roomSeq = "457", roomName = "Execu Room", tariffRequests = new[] { new { tarifSeq = "gfgfgf", plan = "tyt" } } },
new { roomSeq = "222", roomName = "NonRoom", tariffRequests = new[] { new { tarifSeq = "gfgfg", plan = "tyty" } } } }
},


This part how to use in for loop
Member 10918596 14-Sep-15 9:02am    
above list i need to implement via dynamic in for loop??
Thanks7872 14-Sep-15 9:35am    
Then implement it. What is the issue?
Prakash J 14-Sep-15 11:21am    
I don't how to use above list in for loop

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