using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; using TEAMModelOS.SDK.Extension; namespace TEAMModelOS.SDK { /// /// 文件方法 /// public static class FileWay { /// /// 读取文件类容替换方法 /// /// /// /// /// /// public static string FileValue(string rootPath, string fileLang, string keyType, Dictionary replaceData) { string name = ""; string path = Path.Combine(rootPath, $"LogLang/{fileLang}.json"); var sampleJson = File.ReadAllBytes(path).AsSpan(); Utf8JsonReader reader = new Utf8JsonReader(sampleJson); if (JsonDocument.TryParseValue(ref reader, out JsonDocument jsonDoc) && jsonDoc.RootElement.TryGetProperty(keyType, out JsonElement json)) { string msgs = json.ToObject(); if (!string.IsNullOrEmpty(msgs)) { replaceData.Keys.ToList().ForEach(x => { msgs = msgs.Replace("{" + x + "}", $"{replaceData[x]}"); }); name = msgs; //notifyData.body = msgs[1]; } } return name; } } }