in ASP.NET MVC I got an exception that exceeded RecursionLimit when I try to send data to the browser via JSON.
how can i make it work no matter how big the json is.
The default value for the property RecursionLimitis 100, which means that it can serialize objects nested at a depth of 100 objects that reference each other.
RecursionLimit
, , , , , , , , .
, . JSON , . Ayende Rahien .
JSON Serialize, , . My Users , , :
Users oSuperior; [ScriptIgnore(), XmlIgnore()] public Users Superior { get { if (oSuperior == null) { oSuperior = new Users(); if (iIDUserSuperior > 0) oSuperior.Load(iIDUserSuperior); } return oSuperior; } }
, Microsoft JsonResult Class JSON .NET framework 4.5:
public ActionResult GetJson() { var result = Json(obj); result.RecursionLimit = 1024; result.MaxJsonLength = 8388608; return result; }
, , "" JSON, .
ASP.NET MVC:
<system.web.extensions> <scripting> <webServices> <jsonSerialization recursionLimit="1024"/> </webServices> </scripting> </system.web.extensions>
:
new System.Web.Script.Serialization.JavaScriptSerializer(){RecursionLimit = 1024}.Serialize(@Model)
MVC, 100:
Json.Encode(@Model)
, , .
In addition to the above methods, you can replace the default JSON serialization with the one provided by Json.NET, which by default does not have an explicit restriction :
A value of zero means that there is no maximum. The default value is null.
eg:.
JsonConvert.SerializeObject(theObject);
NOTE. ASP.NET Web API uses this default JSON serializer .