从JQuery(AJAX)中的复杂JSON对象中提取数据 [英] Extracting Data from complex JSON objects in JQuery (AJAX)

查看:291
本文介绍了从JQuery(AJAX)中的复杂JSON对象中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我现在已经遇到问题几天了,我真的可以使用一些帮助。

我正试图传递一些数据从C#方法到Jquery中的WebPage的复杂JSON对象的形式,这是我的方法在C#



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#

[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;
   }



,这是我从Jquery方面调用方法




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 ");
   }
});





我的Ajax调用成功,我拥有tableData中的所有数据,这里开始我需要你帮助的土地我不知道如何提取所有数据。

谢谢。



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.

推荐答案

.ajax( {
类型:POST,
url:Default.aspx / getAllDealsInfo,
data:'{}',
contentType:application / json; charset = utf -8,
dataType:json,
成功:函数(_ ObjDeals){
var tableData =
.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]);
},
错误:function(x,e){
alert(对服务失败的调用);
}
});
.parseJSON(_ObjDeals.d); alert(tableData[rows][row]); }, error: function (x, e) { alert("The call to the serve Failed "); } });





我的Ajax调用成功,我拥有tableData中的所有数据,这里开始我需要你帮助的地方我不知道如何提取所有数据。

谢谢。



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.


1。如果在填充tableData后放置一个断点,你可以将tableData放入监视窗口并检查它。

2.如果你谷歌搜索.parseJSON,你会发现很多如何做的例子。

3.一种方法是使用eval

4.你可能必须与#3一起使用的另一种方法是(tabiData中的var i)或者其他一些解析。
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.


这篇关于从JQuery(AJAX)中的复杂JSON对象中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆