hi im trying to parse json obj using JsonConvert.DeserializeObject<>() function
i have created a class to map my json object to , also my json obj is in a c# sharp file that i import
in a class that manage my json database
the problem is when i deserialized the json object to my class and used it used it outside of class i get
the key of the json object but the value is null
her is my code:
namespace DigimonsDex
{
public class DigiDex
{
private Dictionary<string,Digimon> digimons;
private string digimons_json;
public DigiDex()
{
var jsonSettings = new JsonSerializerSettings()
{
MissingMemberHandling = MissingMemberHandling.Error
};
digimons_json = Digimon_database.generateDigimonJsonData();
string jsonResult = JsonConvert.DeserializeObject(digimons_json).ToString();
digimons = JsonConvert.DeserializeObject<Dictionary<string, Digimon>>(jsonResult,jsonSettings);
}
public Digimon getDigimonByName(string digimon_name)
{
return this.digimons[digimon_name];
}
public Dictionary<string, Digimon> getallDigimons()
{
return digimons;
}
}
}
my class that i use for storying the json obj:
public class Digimon
{
public int num { get; set; }
public string name { get; set; }
public string gender { get; set; }
public string stage { get; set; }
public string type { get; set; }
public List<string> attribute { get; set; }
public BaseStats baseStats { get; set; }
public List<string> abilities { get; set; }
public string color { get; set; }
public List<string> eggGroups { get; set; }
public int memoryusage { get; set; }
}
public class BaseStats
{
public int hp { get; set; }
public int atk { get; set; }
public int def { get; set; }
public int spa { get; set; }
public int spd { get; set; }
public int spe { get; set; }
}
the error im getting:
NullReferenceException: Object reference not set to an instance of an object
logic.getDigimonSpeed (System.String digimon_name) (at Assets/logic.cs:230)
logic.setTurnBar (System.Collections.Generic.List`1[T] digimonlist) (at Assets/logic.cs:238)
SceneLogic.Start () (at Assets/SceneLogic.cs:22)
pleas advise me regarding this issue
thanks in advance