Example #1
0
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "application/json";
     var objToSerialize = ...
                          SerializerClass.MyDataContractJsonSerializer(
         objToSerialize,
         objToSerialize.GetType(),
         context.Response.OutputStream
         );
 }
        public string ToJson()
        {
            DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(SerializerClass));
            var sc = new SerializerClass()
            {
                Id                  = this.Id,
                Name                = Name,
                IsDimmable          = LampDetails_Dimmable,
                SupportsColor       = LampDetails_Color,
                SupportsTemperature = LampDetails_VariableColorTemp,
                Hue                 = LampState_Hue,
                Saturation          = LampState_Saturation,
                Brightness          = LampState_Brightness,
                ColorTemp           = LampState_ColorTemp,
                IsOn                = LampState_OnOff,
            };

            using (MemoryStream ms = new MemoryStream())
            {
                s.WriteObject(ms, sc);
                return(System.Text.Encoding.UTF8.GetString(ms.ToArray()));
            }
        }
 public string ToJson()
 {
     DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(SerializerClass));
     var sc = new SerializerClass()
     {
         Id = this.Id,
         Name = Name,
         IsDimmable = LampDetails_Dimmable,
         SupportsColor = LampDetails_Color,
         SupportsTemperature = LampDetails_VariableColorTemp,
         Hue = LampState_Hue,
         Saturation = LampState_Saturation,
         Brightness = LampState_Brightness,
         ColorTemp = LampState_ColorTemp,
         IsOn = LampState_OnOff,
     };
     using (MemoryStream ms = new MemoryStream())
     {
         s.WriteObject(ms, sc);
         return System.Text.Encoding.UTF8.GetString(ms.ToArray());
     }
 }