Modificar estados de espacios
Publicado por Meta (138 intervenciones) el 05/03/2023 02:56:09
Hola:
Teniendo este código para guardar archivo.json.
Crea un archivo y dentro de ella pone.
La idea es hacerlo así:
Según el enlace de abajo hay que activarlo a true.
https://learn.microsoft.com/es-es/dotnet/api/system.text.json.jsonserializeroptions.writeindented?view=net-7.0#system-text-json-jsonserializeroptions-writeindented
¿Cómo lo activo?
Saludos.
Teniendo este código para guardar archivo.json.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Text.Json;
namespace SerializeBasic
{
public class PronosticoDelTiempo
{
public DateTimeOffset Fecha { get; set; }
public int TemperaturaCelsius { get; set; }
public string? Resumen { get; set; }
}
public class Program
{
public static void Main()
{
var pronosticoDelTiempo = new PronosticoDelTiempo
{
Fecha = DateTime.Parse("2019-08-01"),
TemperaturaCelsius = 25,
Resumen = "Caliente."
};
string nombreDelArchivo = "PronósticoDelTiempo.json";
string jsonString = JsonSerializer.Serialize(pronosticoDelTiempo);
File.WriteAllText(nombreDelArchivo, jsonString);
// Crear archivo.
Console.WriteLine(File.ReadAllText(nombreDelArchivo));
// Pulse cualquier tecla para salir.
Console.ReadKey();
}
}
}
Crea un archivo y dentro de ella pone.
1
{"Fecha":"2019-08-01T00:00:00+01:00","TemperaturaCelsius":25,"Resumen":"Caliente."}
La idea es hacerlo así:
1
2
3
4
5
{
"Fecha":"2019-08-01T00:00:00+01:00",
"TemperaturaCelsius":25,
"Resumen":"Caliente."
}
Según el enlace de abajo hay que activarlo a true.
https://learn.microsoft.com/es-es/dotnet/api/system.text.json.jsonserializeroptions.writeindented?view=net-7.0#system-text-json-jsonserializeroptions-writeindented
¿Cómo lo activo?
Saludos.
Valora esta pregunta


0