用Json 讀寫設定餐數檔
先設一個class
//程式參數設定 public class AppSetParam { public string MvcUrl = @"localhost"; public bool TestF = false; }
string App_Path = System.AppDomain.CurrentDomain.BaseDirectory; string Set_name = "_Set.txt"; string set_file = App_Path + "\\" + Set_name; //讀寫參數 AppSetParam MySet; if (!File.Exists(set_file))//不在 就 建立 Json { MySet = new AppSetParam(); string JsonStr = JsonConvert.SerializeObject(MySet); File.WriteAllText(set_file, JsonStr); } else { string RR = File.ReadAllText(set_file); MySet = JsonConvert.DeserializeObject<AppSetParam>(RR); //string ss = MySet.MvcUrl; }
留言
張貼留言