private void btn_works_Click(object sender, EventArgs e) { string json_input = txt_enter.Text; JObject myJson = JObject.Parse(json_input); var artist = GetArtist(myJson); Work work = GetWork(myJson); JToken artistName = myJson.GetValue("name"); //Work artistWork = myJson.SelectToken; var jsonFromFile = System.IO.File.ReadAllText(_path); ArtistGroup artistsData = JsonConvert.DeserializeObject <ArtistGroup>(jsonFromFile); foreach (Artist person in artistsData.artists) { if (person.name.ToString() == artistName.ToString()) { person.works.Add(work); var convertedJson = JsonConvert.SerializeObject(artistsData, Formatting.Indented); System.IO.File.WriteAllText(_path, convertedJson); break; //add new work to existing works list } } }
private void btn_artist_Click(object sender, EventArgs e) { string json_input = txt_enter.Text; JObject myJson = JObject.Parse(json_input); var artist = GetArtist(myJson); var jsonFromFile = System.IO.File.ReadAllText(_path); //var newArtist = JsonConvert.SerializeObject(artist, Formatting.Indented); ArtistGroup artistsData = JsonConvert.DeserializeObject <ArtistGroup>(jsonFromFile); //string blah = ""; artistsData.artists.Add(artist); var convertedJson = JsonConvert.SerializeObject(artistsData, Formatting.Indented); System.IO.File.WriteAllText(_path, convertedJson); //break here }