JsonHandler.ashx.cs


Dosyayı İndir
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace SampleWeb
{
    /// <summary>
    /// Summary description for JsonHandler
    /// </summary>
    public class JsonHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            //context.Response.Write("{\r\n");
            //context.Response.Write("  \"Sample\" : {\r\n");
            //context.Response.Write("    \"sampleId\": 1234,\r\n");
            //context.Response.Write("    \"sampleName\": \"Örnek Adı\",\r\n");
            //context.Response.Write("    \"sampleValue\": 12.34\r\n");
            //context.Response.Write("  }\r\n");
            //context.Response.Write("}");
            ExampleEntities db = new ExampleEntities();
            Sample sample = db.Samples.Single(s => s.SampleId== 2);
            //context.Response.Write("{\r\n");
            //context.Response.Write("  \"Sample\" : {\r\n");
            //context.Response.Write("    \"sampleId\": " + sample.SampleId+ ",\r\n");
            //context.Response.Write("    \"sampleName\": \""+ sample.SampleName+"\",\r\n");
            //context.Response.Write("    \"sampleValue\": " + sample.SampleValue + "\r\n");
            //context.Response.Write("  }\r\n");
            //context.Response.Write("}");

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(sample);
            context.Response.Write(json);

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir