I'm a newbie having my first go at importing data from a json file to a c# application. In this case, I'm making an app to organise and manage recipes for a crafting videogame I'm playing.
I have a json file with my recipe info in it;
{
"assembler_recipes":[
{
"ItemProduced":"AI_Limiter",
"ProductionCount":5,
"Resources":{
"iron_Plate":11.25,
"rubber":3.75
},
"Byproducts":{
}
},
{
"ItemProduced":"alclad_Aluminium_Sheet",
"ProductionCount":30,
"Resources":{
"aluminium_Ingot":30,
"copper_Ingot":10
},
"Byproducts":{
}
}, // etc...
]
}
and the format I want it to be in;
public class Recipe
{
public KeyValuePair<Items, decimal> Produces { get; set; }
public Dictionary<Items,decimal> Resources { get; set; }
public Dictionary<Items, decimal> Byproducts { get; set; }
}
This is my method to import it;
public class Recipe_List
{
public Recipe_List()
{
var dataFile = File.ReadAllText("C:\\Users\\drumk\\source\\repos\\Satisfactory_Factory_Planner\\Satisfactory_Objects\\Recipes\\satisfactory_recipes.json");
//Console.WriteLine(dataFile);
var JSONdata = JsonSerializer.Deserialize<List<Recipe>>(dataFile);
foreach(Recipe recipe in JSONdata)
{
Console.WriteLine(recipe);
}
}
}
The data is being imported because if I use Console.WriteLine(dataFile); it prints it to the Console perfectly. But the Deserialize method is just returning "Satisfactory_Objects.Recipes.Recipe", not the data stored in it.
What am I doing wrong?