asp.net - A circular reference was detected while serializing an object of type 'System.Web.HttpContext' -
i want return json object asp.net web service in format {"part_id":"2","part_name":"\u0645\u0633\u062a\u0644\u0632\u0645\u0627 "}
but following error
system.invalidoperationexception: circular reference detected while serializing object of type 'system.web.httpcontext'.
code :
public class service : system.web.services.webservice { public string name; public service() { //uncomment following line if using designed components //initializecomponent(); } [webmethod(description = "your description")] public string functionname() { var = new service { name = "tamzinho" }; javascriptserializer js = new javascriptserializer(); string retjson = js.serialize(a); return retjson; } }
var = new service { name = "tamzinho" }; ... string retjson = js.serialize(a);
this code problem: serialization attempted infinitely because try serialize instance of same class, attempt serialize instance (and on...)
separate data separate object.
eg:
public class myservicedata { public string name { get; set; } public string description { get; set; } } public class service : system.web.services.webservice { public myservicedata getinfo(int partid) { ... data access code var result = new myservicedata() { name = ...; description = ...; }; ... serialize result data javascript return result; } }
Comments
Post a Comment