命名空間:
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}}
}