zoukankan      html  css  js  c++  java
  • .net core 读取json文件

    核心代码

      Program.cs:

    复制代码
    using System;
    using System.IO;
    using Microsoft.Extensions.Configuration;
    
    namespace Demo
    {
        class Program
        {
            static void Main(string[] args)
            {
                //添加 json 文件路径
                var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
                //创建配置根对象
                var configurationRoot = builder.Build();
    
                //取配置根下的 name 部分
                var nameSection = configurationRoot.GetSection("name");
                //取配置根下的 family 部分
                var familySection = configurationRoot.GetSection("family");
                //取 family 部分下的 mother 部分下的 name 部分
                var motherNameSection = familySection.GetSection("mother").GetSection("name");
                //取 family 部分下的 father 部分下的 age 部分
                var fatherAgeSection = familySection.GetSection("father").GetSection("age");
    
                //Value 为文本值
                Console.WriteLine($"name: {nameSection.Value}");
                Console.WriteLine($"motherName: {motherNameSection.Value}");
                Console.WriteLine($"fatherAge: {fatherAgeSection.Value}");
                Console.Read();
            }
        }
    }

     --------------------------------------------------------

    2.

    .net 5 读取脚本运行的参数

     .net 5 读取appsettings.json

    -----对象转换

     

     

    
    
  • 相关阅读:
    Quick Union
    Quick Find (QF)
    ubuntu kylin18 安装NVIDIA驱动
    vim 快捷键(update)
    Qt中的ui指针和this指针
    两种状态机扫描按键,第二种只要三行!!!
    RPi:QT+wiringPi demo程序
    esp-12e折腾
    vfd电子时钟制作
    vfd with stm8
  • 原文地址:https://www.cnblogs.com/zhang-wenbin/p/11382418.html
Copyright © 2011-2022 走看看