Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
I'm stuck with a problem for few days now, I can really use some help.
I'm trying to pass some data which in form of complex JSON object from a C# method to the WebPage in Jquery, here is my method in C#

C#
[WebMethod]
    public static string getAllDealsInfo()
    {
      SqlDataAdapter adp = new SqlDataAdapter("select top 2 de.[Deal Id], de.Merchant,de.Title, de.ImageSmall from dealdatabase de where [Deal Id] < 84520 order by [Deal Id] desc ", connection);
      DataTable dt = new DataTable();
      adp.Fill(dt);
      List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
      Dictionary<string, object> row = null;

      foreach (DataRow dr in dt.Rows)
      {
         row = new Dictionary<string, object>();
         foreach (DataColumn col in dt.Columns)
         {
            row.Add(col.ColumnName, dr[col]);
         }
         rows.Add(row);
      }

      var serializer = new JavaScriptSerializer();
      string json = serializer.Serialize(rows);
      return json;
   }

and here is my Call to method from Jquery side

$.ajax({ 
   type: "POST",
   url: "Default.aspx/getAllDealsInfo",
   data: '{}',
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   success: function (_ObjDeals) {
      var tableData = $.parseJSON(_ObjDeals.d);
      alert(tableData[rows][row]);
   },
   error: function (x, e) {
   alert("The call to the serve Failed ");
   }
});


My Ajax call is successful and i have all the data in "tableData", and here starts the land where I need your help I don't know how to extract all the data.
Thanks.
Posted
Updated 19-May-14 1:55am
v3
Comments
DaveAuld 19-May-14 7:13am    
What do you mean by Extract? What are you trying to do with the data now that you have it in the object tableData?

1 solution

1. If you put a breakpoint after filling in tableData you could put tableData into the watch window and examine it.
2. If you google for .parseJSON you'll find lots of example of how to do it.
3. One way is to use eval
4. Another way, which you might have to use in conjunction with #3 is to do for (var i in tabelData) or some other parsing of it.
 
Share this answer
 
Comments
SohaibX 19-May-14 15:22pm    
Thanks a lot.
ZurdoDev 19-May-14 15:24pm    
Glad to hear it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900