Example #1
0
        public static void WriteJson(this ResponseContext response, object obj)
        {
            response.SetJsonContentType();

            using (var streamWriter = new StreamWriter(response.OutputStream, Encoding.UTF8))
            {
                using (var jsonTextWriter = new JsonTextWriter(streamWriter)
                {
                    Formatting = Formatting.None
                })
                {
                    var jsonSerializer = new JsonSerializer
                    {
                        Converters =
                        {
                            new JsonEnumConverter()
                        },
                    };

                    jsonSerializer.Serialize(jsonTextWriter, obj);
                }
                streamWriter.Flush();
            }
        }