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
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);;
}