如何在.aspx页面方法中接受JSON字符串数组

我使用jQuery ajax将字符串数组传递给页面方法。 一旦到达该页面方法,我需要知道如何处理该数据。 我的目标是将其插入到数据库中但在此之前我需要理解数组。 实际上,它就是这样:{data:theArray}与{data:1,2,3,4,5,6}相关。 但是4,5和6代表底层数据库中的另一行,因此7,8和9也是如此,依此类推。 我是Ajax的新手。

这是jQuery:

//packaging table data for submit to server $("#saveToDB").click(function() { var dataForSubmit = new Array(); //gather all data to array except the "delete" cell, .rowToDelete $('#QueueTable tbody td:not(.rowToDelete)').each(function() { dataForSubmit.push($(this).html()); }); //send array to method callScriptMethod('DailyReceipts.aspx/saveData', { theData: dataForSubmit }); }); function callScriptMethod(url, jsonObject, callback, async) { callback = callback || function() { }; async = (async == null || async); $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: url, data: JSON.stringify(jsonObject), dataType: "json", async: async, success: function(jsonResult) { if ('d' in jsonResult) callback(jsonResult.d); else callback(jsonResult); }, error: function() { alert("Error calling '" + url + "' " + JSON.stringify(jsonObject)); callback([]); } }); } 

这里是页面方法,静态和[WebMethod]:

  [WebMethod] public static void saveData(string[] theData) { //iterate the array for (int i = 0; i < theData.Length; i++) { } } 

这是一篇关于使用jQuery调用.aspx页面方法的文章。

你可以做的是使用该文章中的信息使用参数将JSON格式的字符串发布到方法,然后使用JSON.NET将字符串解析为对象。