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
        }
		
    }
}
相关推荐
wearegogog1232 小时前
C# .NET 文件比较工具 WinForms
开发语言·c#·.net
糖不吃2 小时前
WPF值转换器
c#
Popeye-lxw4 小时前
由罗技 K380 键盘 FN 键模式切换引发的血案
c#
FL16238631294 小时前
C# OpenCvSharp 基于霍夫变换直线检测的文本图像倾斜校正文本图像倾斜校
开发语言·c#
aini_lovee5 小时前
C# 快递单打印系统(万能套打系统)
开发语言·c#
白菜上路6 小时前
C# Serilog.AspNetCore基本使用
c#·serilog
小白不白1116 小时前
C# WinForm 与 VP 二次开发
开发语言·c#
SunnyDays10117 小时前
如何使用 C# 自动调整 Excel 行高和列宽
开发语言·c#·excel
itgather8 小时前
OfficeExcel — Word / Excel DLL 验证台功能介绍
c#·word·excel
云中小生8 小时前
Scrutor:.NET 依赖注入自动化的优雅实现
c#·.net