コード例 #1
0
ファイル: JsonTest.cs プロジェクト: Rai-Ka/travellermap
 public void StringTest()
 {
     StringWriter writer = new StringWriter();
     JsonSerializer serializer = new JsonSerializer();
     serializer.Serialize(writer, "abc123\t\r\n\b\\\" \u0001\u001f");
     Assert.AreEqual(
         "\"abc123\\t\\r\\n\\b\\\\\\\" \\u0001\\u001F\"",
         writer.ToString());
 }
コード例 #2
0
        public static void SendJson(HttpContext context, object o)
        {
            context.Response.ContentType = JsonConstants.MediaType;

            JsonSerializer js = new JsonSerializer();

            // TODO: Subclass this from a DataResponsePage
            SendPreamble(context, JsonConstants.MediaType);
            js.Serialize(context.Response.OutputStream, o);
            SendPostamble(context, JsonConstants.MediaType);
        }
コード例 #3
0
ファイル: XSerializationTests.cs プロジェクト: carbon/Data
        public void TransformPropertyOnSerializationTest()
        {
            var serializer = new JsonSerializer();

            var person = new
            {
                name = "Sue",
                age = 5
            };

            var transformAge = new PropertyTransformation(
                /*name*/ "age",
                /*transform*/ (age) => { return (int)age * 2; }
            );

            var options = new SerializationOptions
            {
                Include = new[] { "age" },
                Transformations = new[] { transformAge }
            };

            var doc = serializer.Serialize(person, options);

            Assert.Equal(@"{
  ""age"": 10
}", doc.ToString());
        }
コード例 #4
0
        private void SendJson(object o)
        {
            Response.ContentType = JsonConstants.MediaType;
            JsonSerializer js = new JsonSerializer();

            // TODO: Subclass this from a DataResponsePage
            SendPreamble(JsonConstants.MediaType);
            js.Serialize(Response.OutputStream, o);
            SendPostamble(JsonConstants.MediaType);
        }