Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   .NET-Sprachen (https://www.delphipraxis.net/82-net-sprachen/)
-   -   C# Json in .NET Core 2.0 (https://www.delphipraxis.net/194035-json-net-core-2-0-a.html)

franktron 10. Okt 2017 10:13

Json in .NET Core 2.0
 
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

vagtler 10. Okt 2017 10:34

AW: Json in .NET Core 2.0
 
Wo ist DB initialisiert?

franktron 10. Okt 2017 11:19

AW: Json in .NET Core 2.0
 
Danke das wars


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:04 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz