© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
21 replies
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;
        }
    }
}
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;
        }
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ NodaTime JSON Serialization
C#CC# / help
2y ago
❔ JSON serialization fails
C#CC# / help
3y ago
Newtonsoft.Json Serialization Exception
C#CC# / help
3y ago
❔ JSON Serialization Weird Model
C#CC# / help
4y ago