I have a json file - WorkflowNames.json
with contents as -
["ImportOrder", "ValidateOrder", "ProcessOrder", "ArchiveOrder"]
My C# code to read this json file is -
private Dictionary<string, bool> GetWorkflowNames()
{
var appDataFolder = ConfigurationMgr.GetAppPath("App_Data");
var jsonFilePath = Path.Combine(appDataFolder, "WorkflowNames.json");
JArray workflowNames = (JArray)JsonConvert.DeserializeObject(System.IO.File.ReadAllText(jsonFilePath));
var workflowNamesDictionary = new Dictionary<string, bool>();
foreach (JToken workflowName in workflowNames)
{
workflowNamesDictionary.Add(workflowName.ToString(), false);
}
return workflowNamesDictionary;
}
My code runs fine. But because this is my first attempt to read data from a json file, I am not sure about these -
- As a json standard, any data in json file should be represented as key value pair. If I have just an array to read from json file, is it okay to declare as above?
- Is there any better way, can I improve/simplify above C# code?
Thanks a lot!