Skip to content

Instantly share code, notes, and snippets.

@pablopioli
Created August 15, 2020 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablopioli/04b83f38a3c505e428347bb66a0f196e to your computer and use it in GitHub Desktop.
Save pablopioli/04b83f38a3c505e428347bb66a0f196e to your computer and use it in GitHub Desktop.

Agregar serializacion a un proyecto

Abrir una linea de comando en la carpeta del proyecto, instalar la libreria Newtonsoft.Json con

dotnet add package Newtonsoft.Json

Para serializar un objeto al formato Json realizar

Newtonsoft.Json.JsonConvert.SerializeObject(objeto);

donde objeto es cualquier tipo de objeto, incluyendo colecciones.

Como resultado se obtiene un string con los datos del objeto en formato Json.

Para reconstruir el objeto en base al string realizar Newtonsoft.Json.JsonConvert.DeserializeObject(string);

donde T es el tipo de datos, como en

Newtonsoft.Json.JsonConvert.DeserializeObject(string);

Para simplificar el uso agregar el using

using Newtonsoft.Json;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment