Tajkumar goud

Tajkumar goud

  • NA
  • 1
  • 1.9k

how to bind multi level json data to a repeater

Jun 10 2015 2:17 PM
I have to bind json data to a repeater i have found one method. i am able to bind the first level of json data. i am unable to bind the second level of json data repeater inside the repeater.
here is my json input
 
  1. {"apiAvailableBuses": [{"droppingPoints":null,"availableSeats":40,"partialCancellationAllowed":false,"    arrivalTime":"01:00 AM","cancellationPolicy":"   [{\"cutoffTime\":\"1\",\"refundInPercentage\":\"10\"},{\"cutoffTime\":\"2\",\"refundInPercentage\":\"50\"},{\"cutoffTime\":\"4\",\"refundInPercentage\":\"90\"}]","boardingPoints":[{"time":"07:40PM","location":"K.P.H.B,Beside R.S Brothers","id":"2238"}],"operatorName":"Apple I Bus","departureTime":"8:00 PM","mTicketAllowed":false,"idProofRequired":false,"serviceId":"6686","fare":"1000","busType":"Hi-Tech A/c","routeScheduleId":"6686","commPCT":9.0,"operatorId":203,"inventoryType":0}, { "droppingPoints":null,"availableSeats":41,"partialCancellationAllowed":false,"arrivalTime":"06:00 AM","cancellationPolicy":"[{\"cutoffTime\":\"1\",\"refundInPercentage\":\"10\"},{\"cutoffTime\":\"2\",\"refundInPercentage\":\"50\"},{\"cutoffTime\":\"4\",\"refundInPercentage\":\"90\"}]","boardingPoints":[{"time":"08:00PM","location":"Punjagutta,","id":"2241"}],"operatorName":"Royalcoach Travels","departureTime":"8:00 PM","mTicketAllowed":false,"idProofRequired":false,"serviceId":"6736","fare":"800","busType":"VOLVO","routeScheduleId":"6736","commPCT":9.0,"operatorId":243,"inventoryType":0}  

Code 
  1. private void BindItemsInCart(List<apiAvailableBuses> ListOfSelectedProducts)   
  2. {   
  3.     // The the LIST as the DataSource   
  4.     this.rptItemsInCart.DataSource = ListOfSelectedProducts; // Then bind the repeater // The public properties become the columns of your repeater   
  5.     this.rptItemsInCart.DataBind(); } public void getavailablebuses() { string url = string.Format(HttpContext.Current.Server.MapPath("files/getavailablebuses.json")); using (WebClient client = new WebClient()) { string json = client.DownloadString(url); var result = JsonConvert.DeserializeObject<RootObject>(json); string mm = JObject.Parse(json).SelectToken("apiAvailableBuses").ToString();  
  6.      //  var boardingpoint = JObject.Parse(mm).SelectToken("boardingPoints").ToString();  
  7.      var Availablebuses = JObject.Parse(json).SelectToken("apiAvailableBuses").ToString(); DataTable dt = (DataTable)JsonConvert.DeserializeObject(Availablebuses, (typeof(DataTable))); BindItemsInCart(result.apiAvailableBuses); } public class apiresult     { public string message { getset; } public string success { getset; } } public class RootObject { public apiresult apiStatus; public List<apiAvailableBuses> apiAvailableBuses{ getset; }  
  8.     // public string apiAvailableBuses { get; set; }  
  9. }  
  10.   
  11. public class apiAvailableBuses     
  12. {  
  13.     public string serviceId { getset; }   
  14.     public string fare { getset; }   
  15.     public string busType { getset; }   
  16.     public string departureTime { getset; }   
  17.     public string operatorName { getset; }   
  18.     public string cancellationPolicy { getset; }   
  19.     public List<boardingpoints> boardingpoints { getset; }   
  20.     public string droppingPoints { getset; }   
  21.     public string inventoryType { getset; }   
  22.     public string routeScheduleId { getset; }   
  23.     public int availableSeats { getset; }   
  24.     public string arrivalTime { getset; }   
  25.     public Boolean idProofRequired { getset; }  
  26.     public Boolean partialCancellationAllowed { getset; }   
  27.     public int operatorId { getset; }  
  28.     public double commPCT { getset; }   
  29.     public string mTicketAllowed { getset; } }  
  30.     public class boardingpoints  {   
  31.     public string location { getset; }   
  32.     public string id { getset; }   
  33.     public string time { getset; }   
  34. }   
  35.   
  36. public class cancellationPolicy    
  37. {  
  38.  public string cutoffTime { getset; }   
  39.  public string refundInPercentage { getset; }   
  40. }  
 
Here i am able to bind the data to the repeater i want to bind the boardingpoints data to the dropdownlist or another repeater inside that repeater how to do that please help me i am sleepless from so many days. Thank You in advance