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
        }
		
    }
}
相关推荐
sali-tec19 小时前
C# 基于halcon的视觉工作流-章66 四目匹配
开发语言·人工智能·数码相机·算法·计算机视觉·c#
Irene19911 天前
Prettier 配置文件 .prettierrc.js 和 .prettierrc.json 的区别
javascript·json
ITMr.罗1 天前
深入理解EF Core更新机制(开发中因为省事遇到的问题)
服务器·数据库·c#·.net
用户4488466710601 天前
.NET进阶——深入理解委托(3)事件入门
c#·.net
赵庆明老师1 天前
NET 中,你可以使用LINQ 根据指定字段排序
c#·linq
23G1 天前
Fastjson转换jsonStr时设置SerializerFeature.DisableCircularReferenceDetect不生效
json
函数的彼端1 天前
iOS Model Generator - 让 JSON 转模型变得简单高效
ios·json·cocoa
武藤一雄1 天前
C# 万字拆解线程间通讯?
后端·微软·c#·.net·.netcore·多线程
lljss20201 天前
C# 定时器类实现1s定时器更新UI
开发语言·c#
白杨攻城狮1 天前
C# 关于 barierr 心得
开发语言·c#