© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
48 replies
SimplyKazuki

WPF read and write to Json [Answered]

The title says it all, I don't know how to read and write to Json properly. I tried some things but they don't seem to work
        static List<persondata> persondata()
        {
            string fileName = @"C:\Users\elko\source\repos\JsonData\JsonData\bin\Debug\net6.0-windows\Persons.json";
            if (File.Exists(fileName))
            {
                var persons = JsonConvert.DeserializeObject<List<persondata>>
                    (File.ReadAllText(fileName));

                return persons;
            }
            return null;
        }
    }
        static List<persondata> persondata()
        {
            string fileName = @"C:\Users\elko\source\repos\JsonData\JsonData\bin\Debug\net6.0-windows\Persons.json";
            if (File.Exists(fileName))
            {
                var persons = JsonConvert.DeserializeObject<List<persondata>>
                    (File.ReadAllText(fileName));

                return persons;
            }
            return null;
        }
    }

i have looked for tutorials guides everywhere, but nothing worked for me. I must be doing something wrong
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

Can't read Json in WPF
C#CC# / help
4y ago
❔ Newtonsoft json own read write method
C#CC# / help
3y ago
How to write function in .net6? [Answered]
C#CC# / help
4y ago