在我的程序中,我有一个用于模型验证的ActionFilter类。动作过滤器正常工作以验证模型。但问题是在验证JSON对象之前,JSON.Net反序列化JSON对象,我需要知道该JSON对象的属性的数据类型。任何人都可以给我一个建议,我如何在JSON对象中找到属性的数据类型。我的Action Filter类如下:
public class MyModelValidatorFilter: IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
if (context.ModelState.IsValid)
return;
var errors = new Dictionary<string, string[]>();
foreach (var err in actionContext.ModelState)
{
var itemErrors = new List<string>();
foreach (var error in err.Value.Errors){
itemErrors.Add(error.Exception.Message);
}
errors.Add(err.Key, itemErrors.ToArray());
}
actionContext.Result = new OkObjectResult(new MyResponse
{
Errors = errors
});
}
}