Hello,
Welcome to our Microsoft Q&A platform!
using JsonConvert.DeserializeObject<Dictionary<string, JsonContent>>
to deserialize the JSON data
Dictionary<string, JsonContent> jsonData = JsonConvert.DeserializeObject<Dictionary<string, JsonContent>>(jsonString);
foreach (var item in jsonData)
{
Debug.WriteLine("Date:>>" + item.Key);
Debug.WriteLine("color:>>" + item.Value.color);
Debug.WriteLine("message:>>" + item.Value.message);
}
Or change the JSON type, JSON data need key-value format, but 01-01-2017
do not have a key. Based on your JsonContent.cs
, your JSON file need like this
{
"JsonContent":[
{"date":"01-01-2017","color":"white","message":"The Octave Day of Christmas Solemnity of the Blessed Virgin Mary, the Mother of God Lectionary: 18"},
{"date":"02-01-2017","color":"white","message":"Memorial of Saints Basil the Great and Gregory Nazianzen, Bishops and Doctors of the Church Lectionary: 205"}
]
}
Model Class need add Root.cs
like following code.
public class JsonContent
{
public string date { get; set; }
public string color { get; set; }
public string message { get; set; }
}
public class Root
{
public List<JsonContent> JsonContent { get; set; }
}
You can DeserializeObject with Newtonsoft.Json
nuget package.
Root data = JsonConvert.DeserializeObject<Root>(jsonString);
List<JsonContent> jsonContents= data.JsonContent;
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.