.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 core 读取json文件的更多相关文章
- 使用.net core读取Json文件配置
1.使用vs2017创建一个应用台程序 2.使用程序包管理器控制台执行命令 Install-Package Microsoft.AspNetCore -Version 2.0.1 3.创建一个json ...
- spring注解读取json文件
开发时候在接口没有提供的时候,可以用json文件提前模拟接口数据 1.service层 package com.syp.spring.service; import java.io.File; imp ...
- .net core读取json格式的配置文件
在.Net Framework中,配置文件一般采用的是XML格式的,.NET Framework提供了专门的ConfigurationManager来读取配置文件的内容,.net core中推荐使用j ...
- ASP.NET Core appsettings.json 文件
ASP.NET Core appsettings.json 文件 在本节中,我们将讨论 ASP.NET Core 项目中appsettings.json文件的重要性. 在以前的 ASP.NET 版本中 ...
- jquery无法读取json文件问题
jquery无法读取json文件,如:user.json文件无法读取.把user.json文件的后缀名修改为aspx,文件内容不变,则可以读取~ 原理不懂!~~
- Unity 用C#脚本读取JSON文件数据
读取JSON文件数据网上有很多方法吗,这里采用SimpleJSON,关于SimpleJSON的介绍参考以下链接:http://wiki.unity3d.com/index.php/SimpleJSON ...
- cocos2d-x 读取 json 文件并用 jsoncpp 做解析
一码胜万言(请看注释) CclUtil.h // // CclUtil.h // PracticeDemo // // Created by kodeyang on 8/1/13. // // #if ...
- jQuery读取json文件,实现省市区/县(国标)三级联动
最近做一个微信项目,需要用户填写所在的省市区/县,决定使用jQuery读取json文件来实现省市区/县的联动. 其实很简单,jQuery文档也有详细解释: 代码如下: html <table w ...
- jqery ajax读取json文件
json文件数据 [ {"name":"哈哈··","email":"邮箱01","gender": ...
随机推荐
- Corporative Network (有n个节点,然后执行I u,v(把u的父节点设为v)和E u(询问u到根节点的距离))并查集
A very big corporation is developing its corporative network. In the beginning each of the N enterpr ...
- css伪元素::before与::after使用基础示例
1.指定文本前后添加内容 <div class="box">test</div> .box::before{ content: 'before'; marg ...
- Django2.0——模板渲染(一)
在前面的介绍中我们都是用简单的 django.http.HttpResponse来把内容显示到网页上,本节将讲解如何使用渲染模板的方法来显示内容,即调用精美的HTML页面.模板的创建既可以在项目下创建 ...
- Linux-线程常见函数
1.线程创建与回收 (1).pthread_create 主线程用来创造子线程 (2).pthread_join 主线程用来等待(阻塞)回收子线程 (3).pthread_detach 主线程用来 ...
- elk常用知识点
1.让文件每次都从头读取: 当有时候需要重新抽取全日志时候,则需要先删除ES上的索引,然后在logstash上input插件配置sincedb_path => "/dev/null&q ...
- echarts图表重设尺寸
在绘制chart的方法中添加下面语句,则会在尺寸变化的时候,重新绘制图表 window.addEventListener("resize", function () { myCha ...
- 快速dns推荐
中国互联网络中心:1.2.4.8.210.2.4.8.101.226.4.6(电信及移动).123.125.81.6(联通) 阿里DNS:223.5.5.5.223.6.6.6 googleDNS:8 ...
- javaweb学习——JDBC(五)
管理结果集 JDBC使用ResultSet来封装查询到的结果集,然后移动记录指针来取出结果集的内容,除此之外,JDBC还允许通过ResultSet来更新记录,并提供了ResultSetMetaData ...
- HNOI2018/AHOI2018 游戏
这题放过了暴力其实就没啥意思了 虽然暴力复杂度很玄学,但是思维水平确实没啥 Description link 题意概述:现在有一条长度为 \(n\) 的链,有些边是有限制的 限制为能到某个点,才能经过 ...
- placeholder在IE下的兼容问题
最近写项目要求兼容到ie8,写完了去ie测试的时候,发现了placeholder在ie下的兼容问题,为了解决,搜罗网上各种牛人的解决方案,自己总结如下: css样式(设置各浏览器下placeholde ...