public class Jsonresultobject:jsonresult {private Newtonsoft.Json.JsonSerializerSettings Settings { Get Private set; } public Jsonresultobject () {Settings = new Newtonsoft.Json.JsonSerializerSettings {referenceloophandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore} ; public override void Executeresult (ControllerContext context) {if (context = = NULL ) throw new ArgumentNullException ("context"); if (this. Jsonrequestbehavior = = Jsonrequestbehavior.denyget && string. Equals (context. HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)) throw new Invalidoperatione Xception ("JSON GET is not allowed"); var response = context. Httpcontext.response; Response. ContentType = string. IsNullOrEmpty (this. ContentType)? "ApplicatIon/json ": this. ContentType; if (this. ContentEncoding = null) response. ContentEncoding = this. ContentEncoding; if (this. Data = = null) return; var Scriptserializer = Newtonsoft.Json.JsonSerializer.Create (this. Settings); using (var sw = new StringWriter ()) {scriptserializer.serialize (SW, this). Data); Response. Write (SW. ToString ()); } } }
. NET MVC Table Primary foreign key relationship JSON Infinite Loop Scheme II (recommended)