Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generic Class inheritance
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 5.0
OS:
Windows 7
Network:
SAMBA Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01611057
Message ID:
01611291
Vues:
33
>Here it is
>
>
>    public class Destinations
>    {
>        public List<Data> data = new List<Data>();
>    }
>
>    public class Data
>    {
>        public string Destination { get; set; }
>        public string DialCode { get; set; }
>    }
>
>you could:
>
>string path = @"D:\tmp3\myconfig.json";
>
>            Destinations ds = new Destinations();
>
>            ds.data.Add(new Data { Destination = "Hereford", DialCode = "91432" });
>            ds.data.Add(new Data { Destination = "Hay", DialCode = "01497" });
>
>            //Save
>            var j = JsonConvert.SerializeObject(ds);
>            System.IO.File.WriteAllText(path,j);
>
>            //Retrieve and add
>            var j2 = System.IO.File.ReadAllText(path);
>            Destinations ds2 = JsonConvert.DeserializeObject<Destinations>(j2);
>            ds2.data.Add(new Data{Destination = "Monmouth",DialCode = "0600"});
>            System.IO.File.WriteAllText(path,JsonConvert.SerializeObject(ds2));
>
>
Hmm. That code works for me - .i.e after
Destinations ds2 = JsonConvert.DeserializeObject<Destinations>(j2);
ds2 is populated with the list of Data objects. Do you want to post the code you have ?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform