private void onOpenString() { FilenameA = string.Empty; FilecontentA = string.Empty; FileparseA = string.Empty; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); //dlg.Filter = "xml files (*.xml)|*.xml|JSON files (*.json)|*.json"; dlg.Filter = "JSON, XML files (*.json,*.xml)|*.json; *.xml"; Nullable <bool> result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { try { FilenameA = dlg.FileName; FilecontentA = File.ReadAllText(dlg.FileName); FilecontentA = FilecontentA.Trim(); } catch (IOException) { MessageBox.Show("Nije moguce otvoriti odabrani fajl"); } } }
private void onParse() { if (FilecontentA.StartsWith("<") && FilecontentA.EndsWith(">")) { MessageBox.Show("Odabrali ste XML fajl, da li želite da ga parsirate?", "XML - Parsiranje"); parseXML(); } else if (FilecontentA.StartsWith("{") && FilecontentA.EndsWith("}")) { if (FilecontentA.Trim() == "{ }") { FileparseA = "Prazan fajl"; } else { MessageBox.Show("Odabrali ste JSON fajl, da li želite da ga parsirate?", "JSON - Parsiranje"); } parseJSON(); } else { MessageBox.Show("Nije moguce parsirati odabrani fajl"); } }
private void onOpenString() { FilenameA = string.Empty; FilecontentA = string.Empty; FileparseA = string.Empty; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); //dlg.Filter = "xml files (*.xml)|*.xml|JSON files (*.json)|*.json"; dlg.Filter = "JSON, XML files (*.json,*.xml)|*.json; *.xml"; Nullable <bool> result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Open document //string filename = dlg.FileName; // string filecontent = dlg.Title; FilenameA = dlg.FileName; FilecontentA = File.ReadAllText(dlg.FileName); FilecontentT = FilecontentT.Trim(); FilecontentP = FilecontentT.Trim(); if (FilecontentA.StartsWith("<") && FilecontentA.EndsWith(">")) { //XML // To convert an XML node contained in string xml into a JSON string XmlDocument doc = new XmlDocument(); doc.LoadXml(FilecontentA); dynamic jsonDe3 = JsonConvert.SerializeXmlNode(doc); FilecontentP = jsonDe3; } } }