Exemple #1
0
        static void Main(string[] args)
        {
            string json = "{\"Description\":\"Share Knowledge\",\"Name\":\"Surendra\"}";

            using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
            {
                DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(BlogSite));
                BlogSite bsObj2 = (BlogSite)deserializer.ReadObject(ms);
                Console.Write("Name: " + bsObj2.Name);
                Console.Write("Description: " + bsObj2.Description);
            }
            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            BlogSite bsObj = new BlogSite()
            {
                Name        = "Surendra",
                Description = "Share Knowledge"
            };

            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(BlogSite));
            MemoryStream msObj            = new MemoryStream();

            js.WriteObject(msObj, bsObj);
            msObj.Position = 0;
            StreamReader sr   = new StreamReader(msObj);
            string       json = sr.ReadToEnd();

            sr.Close();
            msObj.Close();
            Console.ReadLine();
        }