Hi. Please, could somebody help deserialize JSON from a file. I have no chance to do it alone. The result of the script is a empty dictionary.
P. S. I need to do this to make setting up of troops in unity editor faster
[System.Serializable]
public class TroopValues
{
public int dps;
public int health;
public string name;
public int price;
}
[System.Serializable]
public class LevelList
{
public List<TroopValues> list = new List<TroopValues>();
}
[System.Serializable]
public class TroopsList
{
public Dictionary<string, LevelList> dict = new Dictionary<string, LevelList>();
public static TroopsList CreateFromJSON(string jsonString)
{
return JsonUtility.FromJson<TroopsList>(jsonString);
}
}
// JSON (it is only a part of a json file)
{
"MHN-1": [
"{
\"dps\": 10,
\"health\": 150,
\"name\": \"MHN-1\",
\"price\": 10,
",
"{
"dps": 20,
"health": 200,
"name": "MHN-1",
"price": 20,
",
“{
"dps": 30,
"health": 250,
"name": "MHN-1",
"price": 30,
}”
]
}