Articles → CSHARP → Jsonserializer Class In C#

Jsonserializer Class In C#






Purpose





Example


using System;
using System.Text.Json;

namespace ConsoleApp11
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string json = "{\"Name\": \"Karan Gupta\",\"Age\": 28,\"Technology\": \"JSON\"}";

            Person person= JsonSerializer.Deserialize< Person>(json);

            Console.WriteLine("After Deserializing");
            Console.WriteLine(string.Format("Name:{0}, Age:{1},Technology:{2}", person.Name, person.Age, person.Technology));

            string jsonSerialize = JsonSerializer.Serialize<Person>(person);
            Console.WriteLine("After Serializing");
            Console.WriteLine(jsonSerialize);

            Console.ReadLine();

        }

        public class Person
        {
            public string Name { get; set; }
            public int Age { get; set; }
            public string Technology { get; set; }
        }
    }
}



Output


Picture showing the output of Jsonserializer Class In C#





Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, December 20, 2023

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250