| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 
 | using System.IO;
using Newtonsoft.Json;
 
namespace ConsoleApplication1JsonSerialisation
{
    class Program
    {
        static void Main(string[] args)
        {
 
            //Phase 1  - creation de l'objet
            Contact contact = new Contact() {Nom = "Durand", Prenom = "Albert", Mail = "adurand@gmail.com"};
 
            //Phase 2 - serialisation de l'objet 
            string jsonSerializedObj = JsonConvert.SerializeObject(contact);
            File.WriteAllText(@"c:\temp\monfichierResultat.son", jsonSerializedObj); // il faut que le repertoire c:\temp existe
        }
    }
 
    public class Contact
    {
        public string Nom { get; set; }
        public string Prenom { get; set; }
        public string Mail { get; set; }
    }
} | 
Partager