'Reading Json File in C# coming back null with no errors

Json File:

{
  "ActionName": "JobGenertorTestActions",
  "ActionValue": "Test",
  "AppSource": "JobGeneratorApp",
  "AppText": "This is a test for a job generater app",
  "DetailName": "JobGenertorTestDetails",
  "DetailValue": "Test",
  "Filter": true,
  "FormID": "AccountingCheck",
  "UserID": 12345
}
string JobEditorPath = "C:/Git/JobGeneratorApp/JobGeneratorApp/JobEditor.json";
StreamReader JobEditorReader = new StreamReader(JobEditorPath);

    try
    {
        string jobEditorString = JobEditorReader.ReadToEnd();
        JobInfoLibrary JobEditor = JsonConvert.DeserializeObject<JobInfoLibrary>(jobEditorString);
        JobEditor.AppSource = JobInfo.AppSource;
        JobEditor.AppText = JobInfo.AppText;
        JobEditor.UserID = JobInfo.UserID;
        JobEditor.Filter = JobInfo.Filter;
        JobEditor.FormID = JobInfo.FormID;
        JobEditor.DetailName = JobInfo.DetailName;
        JobEditor.DetailValue = JobInfo.DetailValue;
        JobEditor.ActionName = JobInfo.ActionName;
        JobEditor.ActionValue = JobInfo.ActionValue;
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }

nulls in debug

json during runtime



Solution 1:[1]

you have to swap your instances. You are trying to assign to already assigned

using (StreamReader JobEditorReader = new StreamReader(JobEditorPath))
{

 string json = JobEditorReader.ReadToEnd();
 JobInfoLibrary JobEditor = 
 JsonConvert.DeserializeObject<JobInfoLibrary>(json);

 var JobInfo= new JobInfoLibrary();
 JobInfo.AppSource= JobEditor.AppSource;
... and so on
}

I only don know why you don't use JobInfo instead of JobEditor. You don't need both

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Serge