> 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 ?