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
        }
		
    }
}
相关推荐
hez20104 小时前
.NET 11 Runtime Async 详解
c#·.net·.net core
猿长大人6 小时前
C# | Serilog 新手入门
开发语言·c#·.net·log
在世修行7 小时前
从零打造 C# 工业视觉检测系统(七):串口通信 SerialPort 封装与开发
开发语言·c#·modbus rtu·rs232/rs485
NoteStream11 小时前
【C语言基础】分支和循环(上)
c语言·开发语言·c++·经验分享·笔记·算法·c#
lzhdim14 小时前
C# 通过 Windows API 实现进程内存读写操作
开发语言·windows·c#
-银雾鸢尾-14 小时前
C#中的预处理指令
开发语言·c#
dalong1014 小时前
Savitzky-Golay 的C# 实现
开发语言·kotlin·c#
烟锁池塘柳015 小时前
Conda 创建环境报错:Unable to read repodata JSON file,清华源 pkgs/free 失效解决方法
json·conda
猿长大人15 小时前
C# | Autofac 新手指南:从零理解依赖注入与组件装配
c#·.net·di·依赖注入
show43315 小时前
多格式导出怎么做?2026免费小程序TXT/SRT实践
开发语言·小程序·c#