Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Deserilizing a list of Json Objects only gives me a string of the object name?

I have two projects. One is sending a GET request to the other for a List which is equaivalent to a List for the app sending the request.

When debugging, my responseString equals "System.Collections.Generic.List’1" and in the JSON visualizer says String is not JSON formatted. Why isn’t my response being passed as JSON?

I know there are some methods that .NET has to make things easier but my project is stuck on .NET Framework 4.6.1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This code sends the GET

[HttpGet]
public async Task<bool> GetUnsentApplicationsFromHiring()
{

     try
     {
         using (var client = new HttpClient())
         {
                var uri = new Uri("http://localhost:2904/Home/SendIntermediateApplicationsToDataNet");
                var response = await client.GetAsync(uri);
                var responseString = await response.Content.ReadAsStringAsync();

                var apps = JsonConvert.DeserializeObject<List<EmployeeApplication>>(responseString);

                return true;
         }
     }

This is the code that recives the GET and sends back a List.

[HttpGet]
public async Task<List<JobApplication>> SendIntermediateApplicationsToDataNet()
{
    try
    {
        var apps = DB<JobApplication>().GetAll().Where(x => x.CompletionStatus == CompletionStatusFlag.CompletedStep1
                             || x.CompletionStatus == CompletionStatusFlag.CompletedStep2).ToList();

        foreach(var app in apps)
        {
                
            if (app.CompletionStatus == CompletionStatusFlag.CompletedStep1)
            {
                app.SentCompletionStatus = SentCompletionStatusFlag.SentStep1;
            }
            else
            {
                app.SentCompletionStatus = SentCompletionStatusFlag.SentStep2;
            }
        }
                return apps;
}

>Solution :

Change please this return function to this :

[HttpGet]
public async Task<string> SendIntermediateApplicationsToDataNet()
{
    try
    {
        var apps = DB<JobApplication>().GetAll().Where(x => x.CompletionStatus == CompletionStatusFlag.CompletedStep1
                             || x.CompletionStatus == CompletionStatusFlag.CompletedStep2).ToList();

        foreach(var app in apps)
        {
                
            if (app.CompletionStatus == CompletionStatusFlag.CompletedStep1)
            {
                app.SentCompletionStatus = SentCompletionStatusFlag.SentStep1;
            }
            else
            {
                app.SentCompletionStatus = SentCompletionStatusFlag.SentStep2;
            }
        }
                return JsonConvert.SerializeObject(apps);;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading