I have this object and I want to add an other day to it.
[{
"stone":"5kg",
"years":
[{
"year":"2017",
"stone":"5kg",
"months":
[{
"month":"august",
"stone":"0.5kg",
"days":
[{
"day":"14",
"stone":"0.1kg"
}]
}],
"weeks":
[{
"week":"01",
"stone":"0.5kg"
}]
}]
}]
I have this stored in a file and I deserialize it like so:
string file = System.IO.File.ReadAllText(@"C:\Users\luuk\desktop\test1.json");
var _data = JsonConvert.DeserializeObject<List<Data>>(file);
Now I want to add a day to it but I just can't figure it out. I tried something like this:
_data.Add(new Data()
{
});
string json = JsonConvert.SerializeObject(_data);
System.IO.File.WriteAllText(@"C:\Users\luuk\desktop\test1.json", json);
but I can only access years[] and stone in there.
These are my classes:
public class Data
{
public string stone { get; set; }
public List<Years> years { get; set; }
}
public class Years
{
public string year { get; set; }
public string stone { get; set; }
public List<Months> months { get; set; }
public List<Weeks> weeks { get; set; }
}
public class Months
{
public string month { get; set; }
public string stone { get; set; }
public List<Days> days { get; set; }
}
public class Days
{
public string day { get; set; }
public string stone { get; set; }
}
public class Weeks
{
public string week { get; set; }
public string stone { get; set; }
}
So how can I add an other day to the object?
(I have translated all the variabels in my code from dutch to english so there my be some that I forgot or some typo's)