如何从 net 6 中的 json 设置文件中读取数组

问题描述 投票:0回答:0

我需要阅读 net 6 中的 web api 项目的这一部分

{
  "ProductsMigration": {
    "Products": [
        {
            "Product": 
            {
            "SourceAppId": 4215,
            "TargetAppId": 6218
            }
        }
    ]
  }
}

我创建了这个类:

internal class ProductMigration
{
    internal class ProductMigrationItem
    {
        public string SourceAppId { get; private set; }

        public string TargetAppId { get; private set; }
    }
    public ProductMigrationItem Product { get; set; }

}

这是读取设置的代码:

var items = _Configuration.GetSection("ProductsMigration:Products").Get<ProductMigration[]>();

items.count 为 1 但 SourceAppId 和 TargetAppId 为空。

c# .net configuration-files
© www.soinside.com 2019 - 2024. All rights reserved.