You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azurite修改的冒号分隔扁平化JSON是否合法?如何还原嵌套结构?

关于.NET配置文件中冒号分隔键与扁平化转嵌套的问题

1. 冒号替代点号的写法是否合法?

这种写法完全合法。在.NET的配置系统(包含secrets.json、appsettings.json等配置文件)中,冒号(:)和点号(.)都是配置键的层级分隔符,二者功能等价。配置系统会自动解析带冒号的键,将其映射为嵌套的配置对象,所以你的secrets.json能正常工作是符合预期的。

2. 扁平化JSON转嵌套JSON的正确方式

你提供的扁平化配置内容:

{
  "ConnectionStrings:AzureStorage": "UseDevelopmentStorage=true",
  "ConnectionStrings:AzureStorage:blob": "UseDevelopmentStorage=true",
  "ConnectionStrings:AzureStorage:queue": "UseDevelopmentStorage=true"
}

你尝试的写法不正确——AzureStorage.blob和AzureStorage.queue会被当作ConnectionStrings下的独立一级键,而非AzureStorage的子属性。正确的嵌套格式应该是:

{
  "ConnectionStrings": {
    "AzureStorage": {
      "": "UseDevelopmentStorage=true",
      "blob": "UseDevelopmentStorage=true",
      "queue": "UseDevelopmentStorage=true"
    }
  }
}

注:如果原扁平化配置中ConnectionStrings:AzureStorage的独立值不需要保留,也可以省略空键的写法,只保留blob和queue子属性:

{
  "ConnectionStrings": {
    "AzureStorage": {
      "blob": "UseDevelopmentStorage=true",
      "queue": "UseDevelopmentStorage=true"
    }
  }
}

.NET配置系统对嵌套结构和扁平化的冒号/点号分隔写法完全兼容,只要嵌套结构正确,就能和原扁平化配置实现相同的配置读取效果。

内容的提问来源于stack exchange,提问作者David Thielen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 02:00:08