Einzelnen Beitrag anzeigen

franktron

Registriert seit: 11. Nov 2003
Ort: Oldenburg
1.446 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#1

Json in .NET Core 2.0

  Alt 10. Okt 2017, 10:13
Ich habe eine Json
Code:
{
  "port": 5000,
  "https": false,
  "datenbank": {
    "datenbank": "devtest",
    "password": "12345",
    "port": 3600,
    "server": "lserv",
    "username": "frank"
  }
}
und möchte die auslesen

Code:
public static IConfigurationRoot Configuration { get; set; }
        public static IConfigurationSection Datenbank { get; set; }

        public static int Port { get; set; }
        public static bool Https { get; set; }

        public static dbclass DB { get; set; } 

        public static void Load()
        {
            var builder = new ConfigurationBuilder()
             .SetBasePath(Directory.GetCurrentDirectory())
             .AddJsonFile("config.json");
            Configuration = builder.Build();
            Port = Int32.Parse(Configuration["port"]);
            Https = bool.Parse(Configuration["https"]);
            //bis hier geht es aber danach kommt eine Exception das der wert nicht vorhanden ist
            Datenbank = Configuration.GetSection("datenbank");        
            DB.Port = Datenbank.GetValue<int>("port",3306);
            DB.Server = Datenbank.GetValue<string>("server");
            DB.Name = Datenbank.GetValue<string>("datenbank");
            DB.Username = Datenbank.GetValue<string>("username");
            DB.Password = Datenbank.GetValue<string>("password");
        }
Die exception System.NullReferenceException: "Object reference not set to an instance of an object."
bei DB.Port (DB.Port ist public int Port { get; set; })
Was mache ich da falsch
Frank
Tux sein Lieblingsquellcode
While anzfische<TuxSatt do begin
Fisch:=TFisch.Create; Tux.EssenFisch(Fisch); Fisch.Free;inc(anzfische); end;
  Mit Zitat antworten Zitat