数组的反序列化不支持class

时间:2013-11-29 09:53:03

标签: c# asp.net json

我有以下有效的JSON

{
 "payrollInformation":[ {"EmployeeId":"19","FirstName":"Rebecca","LastName":"Smith","IsHourly":"false","PayFrequency":"102","Amount":"2000","StandardHours":"40","PayGroup":"null","Year":"2013","Sequence":"3","RegularHours":"4","OTHours":"5","DOTHours":"0","Earning":"775","Deduction":"40","RegularHoursIncome":"2000","OverTimeHoursIncome":"15000","DoubleOverTimeHoursIncome":"0","GrossPay":"8775"},{"EmployeeId":"20","FirstName":"Jason","LastName":"Florence","IsHourly":"true","PayFrequency":"0","Amount":"50","StandardHours":"40","PayGroup":"null","Year":"2013","Sequence":"1","RegularHours":"8","OTHours":"4","DOTHours":"0","Earning":"100","Deduction":"115","RegularHoursIncome":"400","OverTimeHoursIncome":"300","DoubleOverTimeHoursIncome":"0","GrossPay":"800"},{"EmployeeId":"21","FirstName":"Peter","LastName":"Schepcozki","IsHourly":"true","PayFrequency":"0","Amount":"50","StandardHours":"40","PayGroup":"null","Year":"2013","Sequence":"1","RegularHours":"6","OTHours":"0","DOTHours":"0","Earning":"525","Deduction":"10","RegularHoursIncome":"300","OverTimeHoursIncome":"0","DoubleOverTimeHoursIncome":"0","GrossPay":"825"},{"EmployeeId":"22","FirstName":"Anita","LastName":"Stone","IsHourly":"true","PayFrequency":"0","Amount":"100","StandardHours":"40","PayGroup":"null","Year":"2013","Sequence":"1","RegularHours":"7","OTHours":"0","DOTHours":"0","Earning":"0","Deduction":"10","RegularHoursIncome":"700","OverTimeHoursIncome":"0","DoubleOverTimeHoursIncome":"0","GrossPay":"700"},{"EmployeeId":"23","FirstName":"John","LastName":"Smith","IsHourly":"true","PayFrequency":"0","Amount":"55","StandardHours":"40","PayGroup":"null","Year":"2013","Sequence":"1","RegularHours":"8","OTHours":"3","DOTHours":"0","Earning":"100","Deduction":"25","RegularHoursIncome":"440","OverTimeHoursIncome":"247.5","DoubleOverTimeHoursIncome":"0","GrossPay":"787.5"},{"EmployeeId":"24","FirstName":"Rachel","LastName":"Crew","IsHourly":"true","PayFrequency":"0","Amount":"69","StandardHours":"40","PayGroup":"null","Year":"2013","Sequence":"1","RegularHours":"4","OTHours":"0","DOTHours":"0","Earning":"150","Deduction":"106","RegularHoursIncome":"276","OverTimeHoursIncome":"0","DoubleOverTimeHoursIncome":"0","GrossPay":"426"}
]
}

当我尝试在我的网络方法中传递此信息作为参数时,我收到以下错误

类不支持反序列化数组

这是我的网络方法的签名

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static bool CalculateTaxes(PayCheckInfoJSON payrollInformation)
        {

我已在我的js中声明 payrollInformation ,如下所示

var PayCheckInfo = { data: [] };

并按照以下

推送js中的项目
PayCheckInfo.data.push({
            "EmployeeId": EmployeeId,
            "FirstName": FirstName,
            "LastName": LastName,
            "IsHourly": IsHourly,

            "PayFrequency": PayFrequency,
            "Amount": Amount,
            "StandardHours": StandardHours,
            "PayGroup": PayGroup,

            "Year": Year,
            "Sequence": Sequence,
            "RegularHours": RegularHours,
            "OTHours": OTHours,
            "DOTHours": DOTHours,

            "Earning": Earning,
            "Deduction": Deduction,

            "RegularHoursIncome": RegularHoursIncome,
            "OverTimeHoursIncome": OverTimeHoursIncome,
            "DoubleOverTimeHoursIncome": DoubleOverTimeHoursIncome,

            "GrossPay": GrossPay



        });

1 个答案:

答案 0 :(得分:0)

将您的c#类标记为:

[serializable]
public class PayCheckInfoJSON
{}