c# - Runtime Error in creating JSON Array ASP.NET -
runtime error in creating json array asp.net
my source code
public class outputjson { public list<entity> android { get; set; } } public class entity { public string name { get; set; } public string version { get; set; } } outputjson = new outputjson{ android = new list<entity> { new entity { name = "aaa", version = "123"}, new entity { name = "bb", version = "34"}, new entity { name = "cc", version = "56"}, } var output = new system.web.script.serialization.javascriptserializer().serialize(outputjson); string yourjsonarray = output; response.clear(); response.contenttype = "application/json; charset=utf-8"; response.write(yourjsonarray ); response.end();
am receiving following error
runtime error description: application error occurred on server. current custom error settings application prevent details of application error being viewed remotely (for security reasons). could, however, viewed browsers running on local server machine. details: enable details of specific error message viewable on remote machines, please create <customerrors> tag within "web.config" configuration file located in root directory of current web application. <customerrors> tag should have "mode" attribute set "off".
what's wrong code?how can solve it?
you can use javascriptserializer
in system.web.script.serialization
name space
please see code below
list<entity> entity = new list<entity>(); javascriptserializer serializer = new javascriptserializer(); string jsonstring = serializer.serialize(entity);
it convert object json string
Comments
Post a Comment