有很多关于如何将 Json.NET 库替换为 ASP.NET MVC 应用程序中的默认序列化程序的资源,但是,在我的一生中,我找不到一个关于如何将其设置为默认反序列化器。
为了说明这一点,这里有一些模板代码:
// how to use Json.NET when deserializing
// incoming arguments?
V
public ActionResult SomeAction ( Foo foo ) {
// this piece of code has lots of resources
// on how to override the default Javascript serializer
return Json(new Bar());
}
在反序列化控制器操作中的传入参数(例如,来自 jQuery AJAX 调用)时,如何告诉我的应用程序使用 Json.NET?
$.ajax({
type : 'POST',
data : { foo : 'bar' }
});
我尝试通过从 Rick StrahlMediaTypeFormatters
调整此资源来适应我的代码,但这也不起作用。请注意,我不在 WebAPI 环境中 --- 但我希望一种适用于正常情况的解决方案应该在.Controller
ApiController