using BPASmartClient.Model; using Model; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.MilkWithTea { public class GLobal { //路径 public static string recipePath = string.Empty; public static string posionPath = string.Empty; public static bool makeEnable = false; public static ObservableCollection MaterialRecipes { get; set; } = new ObservableCollection(); /// /// 设备信息列表 /// public static ObservableCollection deviceConfig { get; set; } = new ObservableCollection(); /// /// 获取Json文件内容,转换成ObservableCollection /// /// /// /// public static ObservableCollection GetJsonToT(string path) { if (!File.Exists(path)) { //创建该文件 File.Create(path); return default; } else { using (StreamReader recipeReader = new StreamReader(path))//读取json文件 { string datacache = ""; string line; while ((line = recipeReader.ReadLine()) != null) //循环将每一行数据拼接为一个完整的字符串 { datacache = datacache + line; } var res = JsonConvert.DeserializeObject>(datacache); //将string转换为class类,从而达到json文件转换的目的 if (res != null) return res; else return new ObservableCollection { }; } } } } }