繁体   English   中英

数组反序列化不支持该类

[英]class is not supported for deserialization of an array

我有以下有效的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



        });

将您的C#类标记为:

[serializable]
public class PayCheckInfoJSON
{}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM