title: How can I serialize object without some property names
body: <p>I want to generate the following json output.I tried to serialize object but as you see from output there is no json string name for "data" array, If its serialized it will add the property name to array. Please suggest a solution for this and optimize it in generic way.This is dummy data orginal Data will be dynamic.</p>
  
  <pre><code>[
      {
          "data": [[0, -74984809.4603082], [1, -1547043466.02543], [2, 1197200673.15602], [3, -1329017076.87315]],
          "label": "Sine Wave"
      },
      {
          "data": [[0, -16009669.0446502], [1, -1349266386.03401], [2, 1730901576.10012], [3, -48303271.446511]],
          "label": "Cosine Wave"
      },
      {
          "data": [[0, -22114801.1769572], [1, 1737206285.30856], [2, 1280894300.93367], [3, -14969166.212896]],
          "label": "Sine2 Wave"
      },
      {
          "data": [[0, -236097551.627018], [1, 8971833.78377865], [2, -805237017.202245], [3, -28865332.2392996]],
          "label": "Cosine2 Wave"
      }
  ]
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Web.Script.Serialization;
  using System.Web.Services;
  using System.Web.UI;
  using Microsoft.Ajax.Utilities;
  
  namespace D3WebApp
  {
      public partial class _Default : Page
      {
          public class Datum
          {
              public int No { get; set; }
  
              public double Value { get; set; }
          }
          public class LineGraphData
          {
              public Datum Data { get; set; }
  
              public string Label { get; set; }
          }
  
          public class GraphData
          {
              public Datum[] Data { get; set; }
  
              public string Label { get; set; }
          }
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
          [WebMethod]
          public static string GetData()
          {
              return GetDataForChart(); ;
          }
  
          private static string GetDataForChart()
          {
              var r1 = new Random();
              var r2 = new Random();
              var r3 = new Random();
              var r4 = new Random();
              var datalist = new List&lt;LineGraphData&gt;();
  
              for (var i = 0; i &lt; 4; i++)
              {
  
                  datalist.Add(new LineGraphData()
                  {
                      Data = new Datum()
                      {
                          No = i,
                          Value = r1.Next() * Math.Sin(r2.Next() + i / (10 * (r4.Next() + .5)))
                      },
                      Label = "Sine Wave"
                  });
  
                  datalist.Add(new LineGraphData()
                  {
                      Data = new Datum()
                      {
                          No = i,
                          Value = r2.Next() * Math.Sin(r3.Next() + i / (10 * (r3.Next() + .5)))
                      },
                      Label = "Cosine Wave"
                  });
                  datalist.Add(new LineGraphData()
                  {
                      Data = new Datum()
                      {
                          No = i,
                          Value = r3.Next() * Math.Sin(r1.Next() + i / (10 * (r2.Next() + .5)))
                      },
                      Label = "Sine2 Wave"
                  });
  
                  datalist.Add(new LineGraphData()
                  {
                      Data = new Datum()
                      {
                          No = i,
                          Value = r4.Next() * Math.Sin(r4.Next() + i / (10 * (r1.Next() + .5)))
                      },
                      Label = "Cosine2 Wave"
                  });
              }
  
              var sb = new StringBuilder();
              var valuelist = new List&lt;GraphData&gt;();
              //want to remove this or make it cleaner
              foreach (var result in datalist.DistinctBy(x =&gt; x.Label).Select(x =&gt; x.Label))
              {
                  var childItems = datalist.
                      Where(x =&gt; x.Label == result).Select(x =&gt; x.Data).ToList();
  
                  valuelist.Add(new GraphData() { Label = result, Data = childItems.ToArray() });
  
                  sb.Append(@"{""data"":");
                  sb.Append("[");
  
                  foreach (var value in childItems)
                  {
                      sb.Append(string.Format("[{0},{1}],", value.No, value.Value));
                  }
  
                  var index = sb.ToString().LastIndexOf(',');
  
                  if (index &gt;= 0)
                      sb.Remove(index, 1);
  
                  sb.Append("],");
                  sb.Append(string.Format(@"""{0}"":""{1}""", "label", result));
                  sb.Append("},");
              }
              var testdata = new JavaScriptSerializer().Serialize(valuelist);
              var datastr = "[" + sb.ToString().Trim(',') + "]";
              return datastr;
          }
      }
  }
  </code></pre>