I have a JSON file I'm trying to deserialize to a list with a dictionary as the values, but struggling with getting the output in a nice format and struggling to index/parse it once it's deserialized. I'm new to this and would appreciate the help. I would like the key/value pairs to look like: {"greeting" : ["greet1": "hey", "greet2" : "hi"]}
JSON file below:
{
"greeting": [
{
"greet1": "hey",
"greet2": "hi"
}
],
"bye": [
{
"bye1": "adios"
}
]
}
Attempted code:
public static Dictionary<string, List<Dictionary<string, string>>> jsonResponses = new Dictionary<string, List<Dictionary<string, string>>>();
public static void DeserializeJsonDict()
{
string jsonURL = HttpContext.Current.Server.MapPath("./theFile.json");
using (var webClient = new System.Net.WebClient())
{
var jsonData = webClient.DownloadString(jsonURL);
jsonResponses = JsonConvert.DeserializeObject<Dictionary<string, List<Dictionary<string, string>>>>(jsonData);
}
}