C#C
C#3y ago
Kensei

❔ ✅ JSON Serialization not working?

Can someone help me with this one, in the MS docs this seems to work just fine, what am i doing wrong..
using System;
using System.Collections.Generic;
using System.Text.Json;

namespace JSONSerialization
{
    class Program
    {
        static void Main(string[] args)
        {    
            Infos infos = new Infos("TestName", 9283943);

            var options = new JsonSerializerOptions { WriteIndented = true };
            string serializedContent = JsonSerializer.Serialize(infos, options);
            Console.WriteLine(serializedContent);
        }
    }
    class Infos
    {
        public string name = "";
        public int id = 0;


        public Infos(string name, int id)
        {
            this.name = name;
            this.id = id;
        }
    }
}
Was this page helpful?