If your project was just an MVC project without WebApi, then Newtonsoft.Json not added to return JsonResults , since the JsonResult returned by MVC uses the JavaScriptSerializer , as shown below:
public override void ExecuteResult(ControllerContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (JsonRequestBehavior == JsonRequestBehavior.DenyGet && String.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(MvcResources.JsonRequest_GetNotAllowed); } HttpResponseBase response = context.HttpContext.Response; if (!String.IsNullOrEmpty(ContentType)) { response.ContentType = ContentType; } else { response.ContentType = "application/json"; } if (ContentEncoding != null) { response.ContentEncoding = ContentEncoding; } if (Data != null) { JavaScriptSerializer serializer = new JavaScriptSerializer(); if (MaxJsonLength.HasValue) { serializer.MaxJsonLength = MaxJsonLength.Value; } if (RecursionLimit.HasValue) { serializer.RecursionLimit = RecursionLimit.Value; } response.Write(serializer.Serialize(Data)); } }
In this case, it was added because WebGrease has a dependency on it. And the binding and minimization services provided by MVC in System.Web.Optimization depend on WebGrease .
Thus, the default MVC application that does not have WebApi will have Newtonsoft.Json installed for the binding and minimization services, not WebApi.
To be clear, the JsonResult returned by WebApi in System.Web.Http uses Newtonsoft.Json to serialize it, as shown below:
using Newtonsoft.Json; using System; using System.IO; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Web.Http; namespace System.Web.Http.Results {
But Newtonsoft.Json not included in the MVC project by default, and if you can use any WebApi, it is there, because, as indicated above, WebGrease needs it. Not sure what they are doing in vNext, possibly Newtonsoft.Json .
source share