I have read a JSON document into a hashtable and started for each loop through the Dinnersets
inside of it.
I have stored the current DinnerSet
in my Helper class and now I just need to use a string named CurrentMeal
which simply contains a mealname
and use it something like this:
String MealID = MyHelper.DinnerSet.Value.Meals.CurrentMeal.MealID
My problem is I don't know how to substitute the String CurrentMeal
into this and have the whole thing expanded to return me the mealID
, If I do this manually:
String MealID = MyHelper.DinnerSet.Value.Meals.Pasta.MealID
I get back the correct MealID
, I am sure it is very simple I just don't know what I should be googling to get onto the right track with this
Any help greatly appreciated
EDIT: JSON Structure example:
"DinnerSet001":
"Version": "0.1",
"Enabled" : true,
"Description": "These are delicious meals for one",
"Notes": "May contain Gluten or Nuts",
"Meals": {
"Pasta": {
"MealID": "MID001",
"Description": "Basic Pasta dish in a tomato and basil sauce",
"Type": "Vegetarian"
},
The way I am reading this JSON into an object is:
dynamic DinnerSetsHash = JsonConvert.DeserializeObject<Dictionary<String, dynamic>>(jsonContent);
I then start reading the Dinnersets inside the JSON using:
foreach (var DinnerSet in DinnerSetsHash) {
I get CurrentMeal from elsewhere but i know it contains the mealnames i need such as "Pasta" and i am then hoping i should then be able to substitute it and get the MealID i need
String MealID = MyHelper.DinnerSet.Value.Meals.CurrentMeal.MealID
Regards
K.