如何在Asp.net Core Web Api中将Newtonsoft.Json用作默认值? [英] How to use Newtonsoft.Json as default in Asp.net Core Web Api?

查看:836
本文介绍了如何在Asp.net Core Web Api中将Newtonsoft.Json用作默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ASP.Net Web Api核心的新手.过去几年我一直在使用 ASP.Net MVC ,并且我一直写ActionFilter并将JSON.Net用于Serializing数据输入到JSON中.因此,以这种方式,我用JSON.Net(据称速度快了400%)代替了Microsoft的JavaScript Serializer(比JSON.Net慢).

I am new to ASP.Net Web Api Core. I have been using ASP.Net MVC for past few years and I always have written an ActionFilter and used JSON.Net for Serializing data into JSON. So, in that way I replaced Microsoft's JavaScript Serializer (which is slower than JSON.Net) with JSON.Net (it is claimed to be 400% faster).

如何在 ASP.Net Web Api Core 中执行所有这些操作?

How to do all this in ASP.Net Web Api Core? Where to change the default formattor?

注意:请随时询问您是否有任何问题.

Note: Please feel free to ask if you have any questions.

谢谢

推荐答案

ASP.NET Core已使用JSON.NET,因为未实现/未将JavaScriptSerializer移植到.NET Core.

ASP.NET Core already uses JSON.NET as JavaScriptSerializer isn't implemented/ported to .NET Core.

Microsoft.AspNetCore.Mvc取决于Microsoft.AspNetCore.Formatter.Json,而Microsoft.AspNetCore.Formatter.Json取决于Newtonsoft.Json(请参阅

Microsoft.AspNetCore.Mvc depends on Microsoft.AspNetCore.Formatter.Json which depends on Microsoft.AspNetCore.JsonPatch, which depends on Newtonsoft.Json (see source).

这仅适用于ASP.NET Core 1.0至2.2. ASP.NET Core 3.0删除了对JSON.NET的依赖,并使用了它自己的JSON序列化程序.

This is only true for ASP.NET Core 1.0 to 2.2. ASP.NET Core 3.0 removes the dependency on JSON.NET and uses it's own JSON serializer.

这篇关于如何在Asp.net Core Web Api中将Newtonsoft.Json用作默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆