jueves, 17 de octubre de 2013

JSON Response C#


private static void JsonResponse(object pObject)
{
try
{
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/json";
response.Charset = "utf-8";

var utf8 = new UTF8Encoding();
String json = JsonConvert.SerializeObject(pObject);
Byte[] encoded = utf8.GetBytes(json);
response.BinaryWrite(encoded);
response.End();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

}

No hay comentarios: