C# 读取JSON文件

命名空间:

cs 复制代码
using System.Text.Json.Nodes;

读取JSON:

cs 复制代码
// 读取设置文件参数
JsonNode json = JsonNode.Parse(File.ReadAllText(Environment.CurrentDirectory.Replace("\\bin\\Debug", "") + "\\settings.json"))["appSettings"];

// 画布参数设置
JsonNode canvas = json["canvas"];
this.qrWidth.Text = canvas["width"].GetValue<int>().ToString();
this.qrHeight.Text = canvas["height"].GetValue<int>().ToString();

settings.json 文件内容:

javascript 复制代码
{
    "appSettings": {
		
        "authorizationCode": {
            "server": "",
            "code": "13014596002",
			
			"msgTitle": "请先授权",
            "msgContent": "请先输入授权码,点击验证按钮!",
			
			"failureTitle": "授权失败",
            "failureContent": "授权失败,校验未通过,请重验证!",
			
			"success": "校验成功"
        },
		
        "canvas": {
            "width": 300,
            "height": 244
        }
		
    }
}
相关推荐
宝桥南山4 小时前
GitHub Models - 尝试一下使用GitHub Models
microsoft·ai·微软·c#·github·.netcore
hixiong1237 小时前
C# OpenvinoSharp部署INSID3
开发语言·人工智能·ai·c#·openvinosharp
星辰徐哥8 小时前
Unity C#入门:变量的定义与访问权限(public/private)
unity·c#·lucene
leoufung8 小时前
LeetCode 30:Substring with Concatenation of All Words 题解(含 C 语言 uthash 实现)
c语言·leetcode·c#
hacker7078 小时前
Visual Studio安装教程(C#开发版)
ide·c#·visual studio
SKY -dada8 小时前
Understand 使用教程
开发语言·c#·流程图·软件构建·敏捷流程·代码复审·源代码管理
William_cl11 小时前
【C#/.NET 进阶】ASP.NET 架构与最佳实践:DI 依赖注入(IoC 核心)从入门到避坑
c#·asp.net·.net
武藤一雄11 小时前
WPF:MessageBox系统消息框
前端·microsoft·c#·.net·wpf
武藤一雄11 小时前
WPF进阶:万字详解WPF如何性能优化
windows·性能优化·c#·.net·wpf·.netcore·鲁棒性
ID_1800790547320 小时前
Python 实现亚马逊商品详情 API 数据准确性校验(极简可用 + JSON 参考)
java·python·json