![]() |
Json in .NET Core 2.0
Ich habe eine Json
Code:
und möchte die auslesen
{
"port": 5000, "https": false, "datenbank": { "datenbank": "devtest", "password": "12345", "port": 3600, "server": "lserv", "username": "frank" } }
Code:
Die exception System.NullReferenceException: "Object reference not set to an instance of an object."
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"); } bei DB.Port (DB.Port ist public int Port { get; set; }) Was mache ich da falsch |
AW: Json in .NET Core 2.0
Wo ist DB initialisiert?
|
AW: Json in .NET Core 2.0
Danke das wars
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 03:01 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz