title: Parsing JSON array of objects
body: <p>I need to store a set of values which I get from my C# code to a javascript array.
  Im getting an error .. Can someone tell what the error is ? 
  Im using this jcode.</p>
  
  <pre><code> $.get('Dataextract.aspx', function (data, textStatus) {
          alert('Status is ' + textStatus);//success
          alert('JSON data string is: ' + data);//string as below
  
      var JSONdata = data;
      eval(JSONdata);//error here-&gt; expected ;
      alert(JSONdata.rowval[0].CustomerID);
  
  }, 'text');
  </code></pre>
  
  <p>I am using an ajax query to retrieve an array of JSON object. the data objects value that i get is something like this as string.</p>
  
  <pre><code>{"rowval" :[{"CustomerID":12"Title":"Mr.""FirstName":"Johnny""MiddleName":"A.""LastName":"Caprio""CompanyName":"Bikes and Motorbikes""RowNumber":10},{"CustomerID":16"Title":"Mr.""FirstName":"Christopher""MiddleName":"R.""LastName":"Beck""CompanyName":"Bulk Discount Store""RowNumber":11},{"CustomerID":18"Title":"Mr.""FirstName":"David""MiddleName":"J.""LastName":"Liu""CompanyName":"Catalog Store""RowNumber":12},{"CustomerID":19"Title":"Mr.""FirstName":"John""MiddleName":"A.""LastName":"Beaver""CompanyName":"Center Cycle Shop""RowNumber":13},{"CustomerID":20"Title":"Ms.""FirstName":"Jean""MiddleName":"P.""LastName":"Handley""CompanyName":"Central Discount Store""RowNumber":14},{"CustomerID":21"Title":"FirstName":"Jinghao""MiddleName":"LastName":"Liu""CompanyName":"Chic Department Stores""RowNumber":15},{"CustomerID":22"Title":"Ms.""FirstName":"Linda""MiddleName":"E.""LastName":"Burnett""CompanyName":"Travel Systems""RowNumber":16},{"CustomerID":23"Title":"Mr.""FirstName":"Kerim""MiddleName":"LastName":"Hanif""CompanyName":"Bike World""RowNumber":17},{"CustomerID":24"Title":"Mr.""FirstName":"Kevin""MiddleName":"LastName":"Liu""CompanyName":"Eastside Department Store""RowNumber":18},{"CustomerID":25"Title":"Mr.""FirstName":"Donald""MiddleName":"L.""LastName":"Blanton""CompanyName":"Coalition Bike Company""RowNumber":19},{"CustomerID":28"Title":"Ms.""FirstName":"Jackie""MiddleName":"E.""LastName":"Blackwell""CompanyName":"Commuter Bicycle Store""RowNumber":20}]}
  </code></pre>
  
  <p>Here is my C# code that is generating the JSON</p>
  
  <pre><code>sb.Append("{\"rowval\" :");
              sb.Append("[");
              if (table != null)
              {
                  foreach (DataRow row in table.Rows)
                  {
                      sb.Append("{");
                      if (row.Table != null &amp;&amp; row.Table.Columns != null &amp;&amp; row.Table.Columns.Count &gt; 0)
                      {
                          foreach (DataColumn column in row.Table.Columns)
                          {
                              parseMember(row[column], column.ColumnName, sb);
                          }
                      }
                      sb.Append("},");
                  }
              }
              sb.Append("]");
              sb.Append("}");
  
              sqlcon.Close();
              Response.Write(sb);
  
  
  
          }
  
          private static void parseMember(object val, string memberName, StringBuilder sb)
          {
              Type t = val.GetType();
  
              if (memberName != null &amp;&amp; memberName.Trim().Length &gt; 0)
                  sb.AppendFormat("\"{0}\":", memberName);
              if (typeof(string) == t || typeof(char) == t)
                  sb.AppendFormat("\"{0}\"", val.ToString());
              else
                  sb.AppendFormat("{0}", val.ToString());
          }
  </code></pre>