Best method to show response in json format?
I am using web application.User can call my aspx page.I am taking input from user in the form of querystring.I want to give response to client in the form of json.Which is best method to show response in json format.try
{
string json = "message{\"description\":\""+description+"\"Id\":\""+id+"}";
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.Write(json);
// Response.End();
HttpContext.Current.Response.Flush(); // Sends all currently buffered output to the client.
HttpContext.Current.Response.SuppressContent = true; // Gets or sets a value indicating whether to send HTTP content to the client.
HttpContext.Current.ApplicationInstance.CompleteRequest();
//HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
or create a class and do serilize.Which one is best method?