title: List under list to convert into json data in C#
body: <p>This is my controller method-</p>
  
  <pre><code> public ActionResult GetTopPaymentWiseCustomer(int? recordNumber, DateTime? spnStartDate, DateTime? spnEndDate)
      {
          var data = _commonService.GetTopPaymentWiseCustomer(recordNumber, spnStartDate, spnEndDate);
          Dictionary&lt;GrantChartViewModel, List&lt;GrantChartDetailsViewModel&gt;&gt; chartData = new Dictionary&lt;GrantChartViewModel, List&lt;GrantChartDetailsViewModel&gt;&gt;();
  
          if (data != null)
          {
              foreach (var item in data)
              {
                  var details = data.Where(o =&gt; o.CustomerId == item.CustomerId);
                  var cl = new GrantChartViewModel
                  {
                      Category = item.RangeName
                  };
                  List&lt;GrantChartDetailsViewModel&gt; detailsList = new List&lt;GrantChartDetailsViewModel&gt;();
                  if (details != null)
                  {
                      foreach (var dl in details)
                      {
                          var d = new GrantChartDetailsViewModel
                          {
                              start = dl.Start,
                              duration = dl.Duration,
                              color = dl.ColorCode,
                              task = dl.TotalPayment.ToString() + "%"
                          };
                          detailsList.Add(d);
                      }
                  }
  
                  chartData.Add(cl, detailsList);
              }
          }
  
          return Json(chartData, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p>And this are my models.. Which need to convert into json like (to plot in amChart (grant chart))- </p>
  
  <pre><code>  var ganttData = [{
                  category: "Customer 1", segments: [
                      { start: 0, duration: 10, color: "#727d6f", task: "40%" },
                      { start: 20, duration: 10, color: "#8dc49f", task: "60%" },
                  ]
              }, {
                  category: "Customer 2", segments: [
                      { start: 15, duration: 10, color: "#727d6f", task: "70%" },
                      { start: 50, duration: 10, color: "#8dc49f", task: "80%" },
                  ]
              }];
  </code></pre>
  
  <p>For a single object(GrantChartViewModel), there will be a list of object (GrantChartDetailsViewModel)</p>
  
  <pre><code> public class GrantChartViewModel
  {
      public GrantChartViewModel()
      {
          listGrantChartDetails = new List&lt;GrantChartDetailsViewModel&gt;();
      }
      public string Category { get; set; }
      public List&lt;GrantChartDetailsViewModel&gt; listGrantChartDetails { get; set; }
  
  }
  
  
  public class GrantChartDetailsViewModel
  {
      public int start { get; set; }
      public int duration { get; set; }
      public string color { get; set; }
      public string task { get; set; }
  }
  </code></pre>
  
  <p>I tried with dictionary but it didn't came out. Any suggestion?  </p>