public static void TxtToJSON() { ObservableCollection <Ryba> oc = new ObservableCollection <Ryba>(); if (File.Exists(pathtxt)) { using (var reader = new StreamReader(pathtxt)) { string line = null; while ((line = reader.ReadLine()) != null) { if (!string.IsNullOrEmpty(line)) { string[] s = line.Split(';'); Ryba r = new Ryba("", "", "", "", "", "", "", 0, 0); r.Nazwa = s[0]; r.ShortName = s[1]; r.Przyneta = s[2]; r.PoraRoku = s[3]; r.PoraDnia = s[4]; r.GdzieZlowione = s[5]; r.GdzieSprzedane = s[6]; r.Waga = Convert.ToInt32(s[7]); r.Cena = Convert.ToInt32(s[8]); oc.Add(r); } } } } PeopleToJson(oc); }
public static void RybaDoJsona(Ryba r) { string jsonString; jsonString = JsonConvert.SerializeObject(r); File.AppendAllText(path, jsonString + Environment.NewLine); //dodaje nową linię -> nową osobę }