hello
how to get API Data have nested table in Datatable in Asp.net c#
string json = (new WebClient()).DownloadString("http://apistaging.ticketsimply.com/gds/api/schedule/318321.json?api_key=TSAPILAXMIHOLIDAYS321");
JToken result = (JsonConvert.DeserializeObject<object>(json) as JObject)["result"];
// object result = JsonConvert.DeserializeObject<object>(json.Replace("{\"result\":", "").Replace("}", ""));
JToken[] jArray = ((result as JArray) as JToken).ToArray();
List<ListItem> items = new List<ListItem>();
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(Int32));
dt.Columns.Add("number", typeof(string));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("service_name", typeof(string));
dt.Columns.Add("origin_id", typeof(string));
dt.Columns.Add("destination_id", typeof(string));
dt.Columns.Add("op_schedule_id", typeof(string));
dt.Columns.Add("travel_date", typeof(string));
dt.Columns.Add("travel_id", typeof(string));
dt.Columns.Add("travels_name", typeof(string));
dt.Columns.Add("route_id", typeof(string));
dt.Columns.Add("route_map_id", typeof(string));
dt.Columns.Add("available_seats", typeof(string));
dt.Columns.Add("description", typeof(string));
dt.Columns.Add("dep_time", typeof(string));
dt.Columns.Add("duration", typeof(string));
dt.Columns.Add("arr_time", typeof(string));
dt.Columns.Add("bus_type", typeof(string));
dt.Columns.Add("cost", typeof(string));
dt.Columns.Add("can_cancel", typeof(string));
dt.Columns.Add("cancellation_time", typeof(string));
dt.Columns.Add("cabin_layout", typeof(string));
dt.Columns.Add("status", typeof(string));
dt.Columns.Add("is_service_tax_applicable", typeof(string));
dt.Columns.Add("helpline_number", typeof(string));
dt.Columns.Add("amenities", typeof(string));
dt.Columns.Add("via", typeof(string));
dt.Columns.Add("bus_layout", typeof(string));
for (int i = 1; i < jArray.Length; i++)
{
DataRow dtrow = dt.NewRow(); // Create New Row
dtrow["id"] = jArray[i][0].ToString().Replace("\"", "");
dtrow["number"] = jArray[i][1].ToString().Replace("\"", "");
dtrow["name"] = jArray[i][2].ToString().Replace("\"", "");
dtrow["service_name"] = jArray[i][3].ToString().Replace("\"", "");
dtrow["origin_id"] = jArray[i][4].ToString().Replace("\"", "");
dtrow["destination_id"] = jArray[i][5].ToString().Replace("\"", "");
dtrow["op_schedule_id"] = jArray[i][6].ToString().Replace("\"", "");
dtrow["travel_date"] = jArray[i][7].ToString().Replace("\"", "");
dtrow["travel_id"] = jArray[i][8].ToString().Replace("\"", "");
dtrow["travels_name"] = jArray[i][9].ToString().Replace("\"", "");
dtrow["route_id"] = jArray[i][10].ToString().Replace("\"", "");
dtrow["route_map_id"] = jArray[i][11].ToString().Replace("\"", "");
dtrow["available_seats"] = jArray[i][12].ToString().Replace("\"", "");
dtrow["description"] = jArray[i][13].ToString().Replace("\"", "");
dtrow["dep_time"] = jArray[i][14].ToString().Replace("\"", "");
dtrow["duration"] = jArray[i][15].ToString().Replace("\"", "");
dtrow["arr_time"] = jArray[i][16].ToString().Replace("\"", "");
dtrow["bus_type"] = jArray[i][17].ToString().Replace("\"", "");
dtrow["cost"] = jArray[i][18].ToString().Replace("\"", "");
dtrow["can_cancel"] = jArray[i][19].ToString().Replace("\"", "");
dtrow["cancellation_time"] = jArray[i][20].ToString().Replace("\"", "");
dtrow["cabin_layout"] = jArray[i][21].ToString().Replace("[", "").Replace("]", "").Replace("\\\"", "").Replace("\"", "");
dtrow["status"] = jArray[i][22].ToString().Replace("\"", "");
dtrow["is_service_tax_applicable"] = jArray[i][23].ToString().Replace("\"", "");
dtrow["helpline_number"] = jArray[i][24].ToString().Replace("\"", "");
dtrow["amenities"] = jArray[i][25].ToString().Replace("\"", "");
dtrow["via"] = jArray[i][26].ToString().Replace("\"", "");
dtrow["bus_layout"] = jArray[i][27].ToString().Replace("\"", "");
dt.Rows.Add(dtrow);
Session["orderdetails"] = dt;
}
GridView1.DataSource = dt;
GridView1.DataBind();