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
        }
		
    }
}
相关推荐
淡海水5 小时前
01-04-认知篇-Unity内存全景
unity·c#·游戏引擎·.net·gc
淡海水15 小时前
01-03-认知篇-C#内存模型深度解析
unity·c#·游戏引擎·.net·gc
星河耀银海16 小时前
数据解析:AI返回JSON数据在HTML5中的渲染方法
人工智能·json·html5
lzhdim21 小时前
C#不为人知的10个魔法特性:资深开发者也会震惊的底层奥秘
java·前端·javascript·算法·c#
三8441 天前
Fastjson 漏洞 · 01 · 认识 Fastjson 与序列化基础
json·fastjson·反序列化
前端 贾公子1 天前
LangChain核心组件 == 提示词(Prompts)
开发语言·c#
一直在努力的小宁1 天前
【阅读笔记】具身操作的数采方案概览
后端·json·restful·具身智能·vla·vlm
码艺-Alimjan1 天前
Web 网站打包桌面应用的另一种方式,超级简单(C# exe 33Kb)
开发语言·前端·c#
海天鹰1 天前
C#入门:显示窗口
c#
淡海水1 天前
16-02-C#常用数据结构源码-附录B-源码索引速查
unity·c#·游戏引擎·il2cpp