命名空间:
using System.Text.Json.Nodes;
读取JSON:
// 读取设置文件参数
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 文件内容:
{
"appSettings": {
"authorizationCode": {
"server": "",
"code": "13014596002",
"msgTitle": "请先授权",
"msgContent": "请先输入授权码,点击验证按钮!",
"failureTitle": "授权失败",
"failureContent": "授权失败,校验未通过,请重验证!",
"success": "校验成功"
},
"canvas": {
"width": 300,
"height": 244
}
}
}