public void FillWithJsonObject(JContainer dict, Scheme scheme) { Title = (string)dict["title"]; Id = (string)dict["id"]; Color = (Color)ColorConverter.ConvertFromString((string)dict["color"]); Points = (dict["points"]).Select(p => new Point((double)p[0], (double)p[1])).ToArray(); }
public virtual void FillWithJsonObject(JContainer dict, Scheme scheme) { Title = (string)dict["title"]; Room = scheme.Rooms.Single(r => r.Id.Equals(dict["room"])); QRCode = (string)dict[@"qr_code"]; Image = (string)dict["image"]; Visible = (bool)dict[@"visible"]; }
public static void WriteJson(Scheme scheme, string jsonPath) { Dictionary<string, object> dict = scheme.ToJsonObject(); string jsonStr = JsonConvert.SerializeObject(dict); Console.WriteLine("json path: {0}", jsonPath); using (StreamWriter w = new StreamWriter(jsonPath)) w.Write(jsonStr); }
public static Scheme ReadJson(string jsonPath) { string jsonStr; using (StreamReader s = new StreamReader(jsonPath)) jsonStr = s.ReadToEnd(); JContainer json = (JContainer)JsonConvert.DeserializeObject(jsonStr); var scheme = new Scheme(); scheme.FillWithJsonObject(json, scheme); return scheme; }
private void Save_Click(object sender, RoutedEventArgs e) { var scheme = new Scheme { Rooms = editor.Rooms.ToArray(), Items = editor.Items.ToArray() }; var dialog = new SaveFileDialog { Filter = "Schemes|*.json||", AddExtension = true }; if (dialog.ShowDialog() == true) { Dictionary<string, object> dict = scheme.ToJsonObject(); string jsonStr = JsonConvert.SerializeObject(dict); File.WriteAllText(dialog.FileName, jsonStr); } }
public void FillWithJsonObject(JContainer dict, Scheme scheme) { Rooms = dict["rooms"].Select(r => { Room room = new Room(); room.FillWithJsonObject((JContainer)r, scheme); return room; }).ToArray(); Items = dict["items"].Select(i => { Item item; string locType = (string)i["location_type"]; if (locType.Equals("room")) item = new RoomItem(); else item = new CoordinateItem(); item.FillWithJsonObject((JContainer)i, scheme); return item; }).ToArray(); }
public override void FillWithJsonObject(JContainer dict, Scheme scheme) { base.FillWithJsonObject(dict, scheme); var l = (JContainer)dict["location"]; Location = new Point((double)l[0], (double)l[1]); }