© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•17mo ago•
5 replies
intee_

✅ Deserialize JSON back into custom object

Hey all,

I have an ObservableCollection that I am using to store a list of tasks (A custom object "TaskItem" that is build like this.

    internal class TaskItem {

        public string Task { get; set; }
        public string Description { get; set; }
        public string Date { get;  }

        public TaskItem()
        {
            Date = DateTime.Now.ToString("hh:mmtt dd/MMM/yyyy");
        }
    }
    internal class TaskItem {

        public string Task { get; set; }
        public string Description { get; set; }
        public string Date { get;  }

        public TaskItem()
        {
            Date = DateTime.Now.ToString("hh:mmtt dd/MMM/yyyy");
        }
    }


And in my ViewModel I'm creating an ObservableCollection of those item types, called "TaskList".

I am exporting that list of TaskItems to Json and that works fine with the below:

            string json = JsonConvert.SerializeObject(TaskList);
File.WriteAllText(SavePath, json)
            string json = JsonConvert.SerializeObject(TaskList);
File.WriteAllText(SavePath, json)


But I can't seem to work out how the hell I load that back into TaskList variable when I re-open the app.

I have been messing around with this in the ViewModel constructor:

string loadedJSON = File.ReadAllText(SavePath);
TaskList = JsonConvert.DeserializeObject<TaskItem>(loadedJSON);
string loadedJSON = File.ReadAllText(SavePath);
TaskList = JsonConvert.DeserializeObject<TaskItem>(loadedJSON);


Trieda bunch of different stuff in there, this was just what I gave up on haha.

Am I at least getting close? haha.
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

Deserialize JSON to dynamic object without Newtonsoft.Json
C#CC# / help
4y ago
JSON Deserialize
C#CC# / help
2y ago
JSON deserialize
C#CC# / help
2y ago
❔ deserialize json object which should be an array
C#CC# / help
4y ago