C# 如何将嵌套json配置绑定到.NETCore中的选项

C# 如何将嵌套json配置绑定到.NETCore中的选项,c#,asp.net,asp.net-core,C#,Asp.net,Asp.net Core,在.NETCore中,如果我们必须直接从Json配置绑定配置,如下所示 { "AzureAdJwtSettings": { "Authority": "https://login.microsoftonline.com/tenantid", }, "WebSecJwtSettings": { "Authority": "https://example.com", } } 我们可以写这样的东西 configuration.Bind("AzureAdJwtSet

在.NETCore中,如果我们必须直接从Json配置绑定配置,如下所示

{  
  "AzureAdJwtSettings": {
    "Authority": "https://login.microsoftonline.com/tenantid",
  },
  "WebSecJwtSettings": {
    "Authority": "https://example.com",
  }
}
我们可以写这样的东西

configuration.Bind("AzureAdJwtSettings", options);
我正在寻找一种方法,以便能够以这种方式对json配置进行分组

{  
  "JwtSettings": {
    "AzureAdJwtSettings": {
      "Authority": "https://login.microsoftonline.com/tenantid"
    },
    "WebSecJwtSettings": {
      "Authority": "https://example.com"
    }
  }
}
但是当我尝试在代码中加载配置时,它没有正确加载。。我正在使用下面的代码

configuration.Bind("JwtSettings.AzureAdJwtSettings", options);

我知道一定有办法加载嵌套属性,但找不到有效的方法…

根据建议的注释,格式应使用冒号(
)而不是点(
),并带有键,以便配置选项绑定工作

比如说

configuration.Bind("JwtSettings:AzureAdJwtSettings", options);
使用冒号(
)代替点(