Advertisement
AmidamaruZXC

Untitled

Jun 6th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.Serialization.Json;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using MessageLib;
  9.  
  10. namespace ConsoleApp2
  11. {
  12.     public class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             try
  17.             {
  18.                 DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(MessageBox));
  19.  
  20.                 using (FileStream fs = new FileStream(@"..\..\..\ConsoleApp1\bin\Debug\messageBox.json", FileMode.Open))
  21.                 {
  22.                     MessageBox messageBox = (MessageBox)jsonFormatter.ReadObject(fs);
  23.  
  24.                     foreach (var message in messageBox)
  25.                         Console.WriteLine(message.ToString());
  26.                 }
  27.             }
  28.             catch (Exception ex)
  29.             {
  30.                 Console.WriteLine(ex.Message);
  31.             }
  32.  
  33.  
  34.             Console.ReadKey();
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement