反序列化时值不能为空

问题描述 投票:0回答:1

型号过滤器:

{
   "StartDateFrom":"",
   "StartDateTo":"",
   "Status":"54C0028F-5A26-4DB9-AC90-B1871E9D3F08",
   "EndDateFrom":"",
   "EndDateTo":"",
   "Style":"B8945C54-0EBB-4FDB-806B-6F1727F04058",
   "LeaveType":"",
   "DateofproductionArray":[
      false,
      ""
   ],
   "BirthdayArray":[
      false,
      ""
   ],
   "IntelligenceconfirmationArray":[
      false,
      ""
   ],
   "DurationArray":[
      false,
      ""
   ],
   "SendbooksbypostArray":[
      false,
      ""
   ],
   "NoticeofleaveArray":[
      false,
      ""
   ],
   "MDnoticeArray":[
      false,
      ""
   ],
   "PayrollnoticeArray":[
      false,
      ""
   ],
   "CheckmytestatusArray":[
      false,
      ""
   ],
   "ShortServicechkArray":[
      false,
      false
   ],
   "LeaveBalancecfmArray":[
      false,
      false
   ],
   "releasedateArray":[
      false,
      ""
   ],
   "JPASloginArray":[
      false,
      ""
   ],
   "SAPloginArray":[
      false,
      ""
   ],
   "ReinstateConfirmationArray":[
      false,
      ""
   ],
   "ReinstatementdateArray":[
      false,
      ""
   ],
   "ReinstatementnoticeArray":[
      false,
      ""
   ],
   "CounselingpracticeArray":[
      false,
      ""
   ],
   "UpdatelistlocalHRArray":[
      false,
      ""
   ],
   "ProgresschkArray":[
      false,
      false
   ]
}
TrackingModel tlModel = new TrackingModel();
tlModel = JsonConvert.DeserializeObject<TrackingModel>(modelFilter)

我收到错误为

[TrackingController] GetMaternityLeave() 值不能为空。参数名称:value_ 在Newtonsoft.Json.JsonConvert.DeserializeObject(字符串值,类型类型,JsonSerializerSettings设置) 在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](字符串值,JsonSerializerSettings 设置) 在 D:\s\Knowing.Web\ECollaboration.Web\Areas\JapanLOA\Controllers\TrackingController.cs 中的 ECollaboration.Web.Areas.JapanLOA.Controllers.TrackingController.GetMaternityLeave(String modelFilter):第 72 行

错误发生在生产中,而不是本地。我不知道为什么。请帮忙。
如何找出哪个参数受到影响或者确实是数据错误?

这就是

TrackingModel
的定义方式。请参阅下文,模型过滤器仅来自生产环境。

c# ajax serialization json.net deserialization
1个回答
0
投票

我认为主要问题是如何创建课程。 例如,这将是键值对的列表/数组

   "CounselingpracticeArray":[
      false,
      ""
   ],

你可以使用asl列表或JArray(稍后解析对象),在我将releaseateArray制作为JArray的示例中

这是正确反序列化的类示例。

void Main()
{
    string json = "{\"StartDateFrom\":\"\",\"StartDateTo\":\"\",\"Status\":\"54C0028F-5A26-4DB9-AC90-B1871E9D3F08\",\"EndDateFrom\":\"\",\"EndDateTo\":\"\",\"Style\":\"B8945C54-0EBB-4FDB-806B-6F1727F04058\",\"LeaveType\":\"\",\"DateofproductionArray\":[false,\"\"],\"BirthdayArray\":[false,\"\"],\"IntelligenceconfirmationArray\":[false,\"\"],\"DurationArray\":[false,\"\"],\"SendbooksbypostArray\":[false,\"\"],\"NoticeofleaveArray\":[false,\"\"],\"MDnoticeArray\":[false,\"\"],\"PayrollnoticeArray\":[false,\"\"],\"CheckmytestatusArray\":[false,\"\"],\"ShortServicechkArray\":[false,false],\"LeaveBalancecfmArray\":[false,false],\"releasedateArray\":[false,\"\"],\"JPASloginArray\":[false,\"\"],\"SAPloginArray\":[false,\"\"],\"ReinstateConfirmationArray\":[false,\"\"],\"ReinstatementdateArray\":[false,\"\"],\"ReinstatementnoticeArray\":[false,\"\"],\"CounselingpracticeArray\":[false,\"\"],\"UpdatelistlocalHRArray\":[false,\"\"],\"ProgresschkArray\":[false,false]}";

    TrackingModel tlModel = new TrackingModel();
    tlModel = JsonConvert.DeserializeObject<TrackingModel>(json).Dump();
}

public class TrackingModel
{
    public DateTime? StartDateFrom { get; set; }
    public DateTime? StartDateTo { get; set; }
    public string Status { get; set; }
    public DateTime? EndDateFrom { get; set; }
    public DateTime? EndDateTo { get; set; }
    public string Style { get; set; }
    public string LeaveType { get; set; }
    public List<KeyValuePair<bool, string>> DateofproductionArray { get; set; }
    public List<KeyValuePair<bool, string>> BirthdayArray { get; set; }
    public List<KeyValuePair<bool, string>> IntelligenceconfirmationArray { get; set; }
    public List<KeyValuePair<bool, string>> DurationArray { get; set; }
    public List<KeyValuePair<bool, string>> SendbooksbypostArray { get; set; }
    public List<KeyValuePair<bool, string>> NoticeofleaveArray { get; set; }
    public List<KeyValuePair<bool, string>> MDnoticeArray { get; set; }
    public List<KeyValuePair<bool, string>> PayrollnoticeArray { get; set; }
    public List<KeyValuePair<bool, string>> CheckmytestatusArray { get; set; }
    public List<bool> ShortServicechkArray { get; set; }
    public List<bool> LeaveBalancecfmArray { get; set; }
    public JArray releasedateArray { get; set; }
    public List<KeyValuePair<bool, string>> JPASloginArray { get; set; }
    public List<KeyValuePair<bool, string>> SAPloginArray { get; set; }
    public List<KeyValuePair<bool, string>> ReinstateConfirmationArray { get; set; }
    public List<KeyValuePair<bool, string>> ReinstatementdateArray { get; set; }
    public List<KeyValuePair<bool, string>> ReinstatementnoticeArray { get; set; }
    public List<KeyValuePair<bool, string>> CounselingpracticeArray { get; set; }
    public List<KeyValuePair<bool, string>> UpdatelistlocalHRArray { get; set; }
    public List<bool> ProgresschkArray { get; set; }
}

结果如你所见:

© www.soinside.com 2019 - 2024. All rights reserved.