Hola:
Antes usaba muchos el XML para guardar y leer datos que tenía en el formulario. Por ejemplo en este caso.
Código:
using System;
using System.Windows.Forms;
using System.Xml;
namespace Guardar_y_cargar_datos_en_archivo_xml
{
* *public partial class Form1 : Form
* *{
* * * *public Form1()
* * * *{
* * * * * *InitializeComponent();
* * * *}
* * * *// Guarda los datos introducidos a parte de crear el archivo "miXML.xml".
* * * *private void button_Guardar_Click(object sender, EventArgs e)
* * * *{
* * * * * *XmlWriter w = XmlWriter.Create("miXML.xml");
* * * * * *w.WriteStartElement("MiInfo");
* * * * * *w.WriteElementString("TextBox", textBox1.Text);
* * * * * *w.WriteElementString("CheckBox", checkBox1.Checked.ToString());
* * * * * *w.WriteElementString("radioButton1", radioButton1.Checked.ToString());
* * * * * *w.WriteElementString("radioButton2", radioButton2.Checked.ToString());
* * * * * *w.WriteEndElement();
* * * * * *w.Close();
* * * *}
* * * *private void Form1_Load(object sender, EventArgs e)
* * * *{
* * * * * *try
* * * * * *{
* * * * * * * *XmlReader r = XmlReader.Create("miXML.xml");
* * * * * * * *r.ReadStartElement("MiInfo");
* * * * * * * *textBox1.Text = r.ReadElementContentAsString();
* * * * * * * *checkBox1.Checked = Convert.ToBoolean(r.ReadElementContentAsString());
* * * * * * * *radioButton1.Checked = Convert.ToBoolean(r.ReadElementContentAsString());
* * * * * * * *radioButton2.Checked = Convert.ToBoolean(r.ReadElementContentAsString());
* * * * * * * *r.ReadEndElement();
* * * * * * * *r.Close();
* * * * * *}
* * * * * *catch (Exception)
* * * * * *{
* * * * * * * *//
* * * * * *}
* * * *}
* *}
}
El archivo se genera en el disco duro o SSD hoy en día y pone esto.
Código:
<MiInfo>
<TextBox>Texto y textos</TextBox>
<CheckBox>True</CheckBox>
<radioButton1>False</radioButton1>
<radioButton2>True</radioButton2>
</MiInfo>
Me funciona de maravilla para lo que es el XML y me lo recomendaron en este foro hace años, desde el 2.008.
Ahora, veo mucho con el santo JSON.
¿Es recomendable usar el JSON?
Si es cierto o no. Quiero hacer el mismo ejemplo de recuperar y guardar datos como se hizo el XML.
Saludos.