问题描述
大家好,
我现在已经遇到问题几天了,我真的可以使用一些帮助。
我正试图传递一些数据从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调用成功,我拥有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.
这篇关于从JQuery(AJAX)中的复杂JSON对象中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!