Hi,
I am trying to convert JSON string to List of Classes in c#, however it is not working as expected… Can You please take a look on my code below and help me to understand what am I doing wrong?
Error message is:
InvalidOperationException: Instance of JsonData is not a dictionary
My code (sorry if it is not formatted well, I don’t know how to do that):
public List pokes = new List();
void Start() {
jsonString = File.ReadAllText(Application.dataPath + “/Pokes/pokeList.json”);
pokeData = JsonMapper.ToObject(jsonString);
pokes = getAllPokeList();
}
public List getAllPokeList()
{
for (int i = 0; i < pokeData.Count; i++)
{
Poke currentPoke = new Poke();
currentPoke.name = pokeData*[“name”].ToString();*
currentPoke.att = (int)pokeData*[“att”];*
currentPoke.def = (int)pokeData*[“def”];*
currentPoke.textureName = pokeData*[“textureName”].ToString();*
currentPoke.baseExp = (int)pokeData*[“baseExp”];*
for (int j = 0; j < pokeData*[“baseMoves”][“move”].Count; j++)*
{
currentPoke.baseMoves[j].moveID = (int)pokeData*[“baseMoves”][“move”][j][“moveID”];*
currentPoke.baseMoves[j].moveLevel = (int)pokeData*[“baseMoves”][“move”][j][“moveLevel”];*
}
for (int k = 0; k < pokeData*[“types”][“type”].Count; k++)*
{
currentPoke.types[k] = pokeData*[“types”][“type”][k].ToString();*
}
pokes.Add(currentPoke);
}
return pokes;
}