无法将JSON字符串化数组传递给PageMethod [英] Trouble Passing JSON Stringified Array to PageMethod
问题描述
我无法将JSON字符串化数组传递给PageMethod
I am having trouble passing a JSON stringified array to a PageMethod
[{
"StartDate": "3/1/2011",
"EndDate": "3/31/2011",
"UserId": "8",
"DdlViewSelectedValue": "zzz#",
"DdlViewSelectedItem": "zzz",
"DdlOrgSelectedValue": "8"
}, {
"StartDate": "3/1/2011",
"EndDate": "3/31/2011",
"UserId": "9",
"DdlViewSelectedValue": "zzz#",
"DdlViewSelectedItem": "zzz",
"DdlOrgSelectedValue": "8"
}, {
"StartDate": "3/1/2011",
"EndDate": "3/31/2011",
"UserId": "5",
"DdlViewSelectedValue": "zzz#",
"DdlViewSelectedItem": "zzz",
"DdlOrgSelectedValue": "8"
}, {
"StartDate": "3/1/2011",
"EndDate": "3/31/2011",
"UserId": "13",
"DdlViewSelectedValue": "zzz#",
"DdlViewSelectedItem": "zzz",
"DdlOrgSelectedValue": "8"
}, {
"StartDate": "3/1/2011",
"EndDate": "3/31/2011",
"UserId": "6",
"DdlViewSelectedValue": "zzz#",
"DdlViewSelectedItem": "zzz",
"DdlOrgSelectedValue": "8"
}, {
"StartDate": "3/1/2011",
"EndDate": "3/31/2011",
"UserId": "11",
"DdlViewSelectedValue": "zzz#",
"DdlViewSelectedItem": "zzz",
"DdlOrgSelectedValue": "8"
}]
当我收到这个ajax请求时,'jsonText'包含上面列出的数据
When I get to this ajax request, 'jsonText' contains the data listed above
function GetUserSchedules() {
var jsonText = $.toJSON(arrParams);
$.ajax({
type: "POST",
url: "/myurl/jquery.aspx/GenerateUserSchedules",
data: "{" + jsonText + "}",
contentType: "application/json",
dataType: "json",
success: AjaxSucceeded
,
error: AjaxFailed
});
}
Pagemethod:
The Pagemethod:
[System.Web.Script.Services.ScriptMethod]
[System.Web.Services.WebMethod]
public static void GenerateUserSchedules(Data[] data)
{
//do stuff; will return data but for now, just keeping it like this
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
}
数据类:
[Serializable]
public class Data
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int UserID { get; set; }
public string ViewSelectedValue { get; set; }
public string ViewSelectedItem { get; set; }
public string OrgSelectedValue { get; set; }
}
每次发送ajax请求时,都会执行错误函数.我在做什么错了?
Every time the ajax request is sent the error function executes. What am I doing wrong?
推荐答案
这是日期的常见问题. JavaScriptSerializer希望采用以下格式的日期才能成功解析它们:
That's a common issue with dates. The JavaScriptSerializer expects dates in the following format in order to parse them successfully:
{
"StartDate": "\/Date(983401200000)\/",
"EndDate": "\/Date(985989600000)\/",
"UserId": "8",
"DdlViewSelectedValue": "zzz#",
"DdlViewSelectedItem": "zzz",
"DdlOrgSelectedValue": "8"
}
其中983401200000
表示自1970年1月1日以来的世界协调时间(UTC)的毫秒数.
where 983401200000
represents the number of milliseconds since January 1, 1970 in Universal Coordinated Time (UTC).
文档中的报价:
日期对象,在JSON中表示为 "\/日期(滴答数)\/".这 滴答数为正或 负的long值,指示 的刻度数(毫秒) 自午夜01起已经过去 1970年1月UTC.
Date object, represented in JSON as "\/Date(number of ticks)\/". The number of ticks is a positive or negative long value that indicates the number of ticks (milliseconds) that have elapsed since midnight 01 January, 1970 UTC.
支持的最大日期值为 MaxValue(12/31/9999 11:59:59 PM)和 支持的最小日期值为 最小值(1/1/0001 12:00:00 AM).
The maximum supported date value is MaxValue (12/31/9999 11:59:59 PM) and the minimum supported date value is MinValue (1/1/0001 12:00:00 AM).
这篇关于无法将JSON字符串化数组传递给PageMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!