Exemplo n.º 1
0
        public void JsonSerializerToStream()
        {
            #region JsonSerializerToStream
            Product product = new Product();
            product.ExpiryDate = new DateTime(2008, 12, 28);

            JsonSerializer serializer = new JsonSerializer();
            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            const string path =
#if UNITY_EDITOR_LINUX || UNITY_EDITOR_OSX || UNITY_STANDALONE_LINUX || UNITY_STANDALONE_OSX
                "/tmp/json.txt"
#else
                @"c:\json.txt"
#endif
            ;

            using (StreamWriter sw = new StreamWriter(path))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, product);
                    // {"ExpiryDate":new Date(1230375600000),"Price":0}
                }
            #endregion
        }
        public void JsonSerializerToStream()
        {
            #region JsonSerializerToStream
            Product product = new Product();
            product.ExpiryDate = new DateTime(2008, 12, 28);

            JsonSerializer serializer = new JsonSerializer();
            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            using (StreamWriter sw = new StreamWriter(@"c:\json.txt"))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, product);
                    // {"ExpiryDate":new Date(1230375600000),"Price":0}
                }
            #endregion
        }