help parsing json object

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

This has nothing to do with JSON. You’re not initializing your collections.

The answer is always the same… ALWAYS!

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Three steps to success:

  • Identify what is null ← any other action taken before this step is WASTED TIME
  • Identify why it is null
  • Fix that

IF you come to a problem with JSON, once you fix the trivia above, keep this in mind:

Also, always be sure to leverage sites like:

https://csharp2json.io

Which line is it erring on because the lines of code you provided do not match the lines in the error.

the error pointing to a function that return the the class containing the data of the json

 public  void setTurnBar(List<Digimon> digimonlist)
{
     string digimon_name = digimonlist[0].name;
     string digimon2_name = digimonlist[1].name;
     int digimon_speed = getDigimonSpeed(digimonlist[0].name.ToLower());
     int digimon2_speed = getDigimonSpeed(digimonlist[1].name.ToLower());
  
}
 public int getDigimonSpeed(string digimon_name)
{
     int digimon_speed = digimons[digimon_name].baseStats["spe"];

for now i know where is the problem , i have a Logicmaneger object that mange my game logics , inside that game object I’m initiating the database manager class and initiate a variable containing my data base , for some reason when I print the variable inside start function I can see my object and its values , but inside other function in the Logicmaeger object script I get keys with null values?

(the database class dos not extend MonoBehaviour class)

problem solved , it seems I needed to initiate my object in Awake() function to initiate my object before scene is started
what case my issue is that I was using the variable contain my data before it is initiated because its waiting for the scene to start to initiate it