using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WDProduceToolUpdate { public class JsonFileHelper { /// /// 将序列化的json字符串内容写入Json文件,并且保存 /// /// 路径 /// Json内容 public static void WriteJsonFile(string path, string jsonConents) { File.WriteAllText(path, jsonConents, System.Text.Encoding.UTF8); } /// /// 获取到本地的Json文件并且解析返回对应的json字符串 /// /// 文件路径 /// public static string GetJsonFile(string filepath) { string json = string.Empty; using (FileStream fs = new FileStream(filepath, FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(fs, Encoding.UTF8)) { json = sr.ReadToEnd().ToString(); } } return json; } } }