Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, i have a method:

I am getting following ERRORS

1. when i using newtonsoft json to convert list to json, my list obj i am getting unformatted like: [\"TC1,TC3,TC9,TC13\",\"TC1,TC3\"] how i can get a neat json format?

2. How i can return a list in task?  return Task.FromResult(result); this is error

3 in my ResultEmployee class i want use only 3 out of 4 but 4th one also returning as null as it is not asigned how to handle that one?


What I have tried:

C#
public Task GetResultsEmployee(string  Id){
    ResultEmployee  ResultEmployee= new ResultEmployee();
    var Gradedemployeess= JsonConvert.SerializeObject(gradedemp); //issue 1. when i using newtonsoft json to convert list to json, my list obj i am getting unformatted like: [\"TC1,TC3,TC9,TC13\",\"TC1,TC3\"] how i can get a neat json format?

    var  TypeList = DistinctTestTypes.Distinct().ToList();
    var salariedemp = JsonConvert.SerializeObject(salariedemp);
    var message = "Total graded employees are " + Gradedemployeess;
    ResultEmployee  .Grade= "A Grade employees";
    ResultEmployee  .Message = message;
    ResultEmployee  .TypeList = TypeList;

   ResultEmployee  .name = name; //issue 3-in my ResultEmployee class i want use only 3 out of 4(am not using "name") but 4th one also returning as null as it is not asigned how to handle that one?
    result.Add(ResultSummary);
    return Task.FromResult(result); // issue 2-How i can return a list in task?  return Task.FromResult(result);
}
Posted
Updated 5-Jul-21 2:59am
v6
Comments
Richard Deeming 5-Jul-21 7:27am    
If you want someone to help you fix an error, you need to tell us what the error is. Just showing a line of code and saying "this is error" tells us precisely nothing.

Click the green "Improve question" link and update your question to include the full details of the error.
[no name] 5-Jul-21 8:41am    
hi, i have explained in the first part with numbers 1,2,3.. all 3 errors,where it happend i just marked in the code like issue 1,2,3 like that.How can i post some snippet without explaining my errors? thats funny :) .Anyway i have updated my question asper ur suggestion,thanks a lot
Richard Deeming 5-Jul-21 8:43am    
"This is error" is the only "explanation" you have given.

You need to provide the full details of the error if you want anyone to be able to help you.

Remember, we cannot see your screen, access your computer, or read your mind. If you don't tell us what the problem is, then we cannot help you.
[no name] 5-Jul-21 8:48am    
I have updated my errors,expecting some help..thank you
Richard Deeming 5-Jul-21 8:51am    
No, you've just added "This is error" as a comment in your code. You have not explained WHAT error you are getting!

If you are unable to explain the problem properly, then nobody will be able to help you.

1 solution

You can't return a list from that method, it is declared as returning a single instance of the Task class. to return a collection, you would have to change the method signature, then create the collection, populate it, and then return it.

That's what null is for - to indicate that there is nothing in a variable, property, or field. There is no other "this doesn't contain anything, please ignore it" value - null is that value!

2) No idea - start by looking at the actual Json data and feed it to a o0nline Json-to-C# class builder (Convert JSON to C# Classes Online - Json2CSharp Toolkit[^] for example) and see what it generates. Then look at where you get the Json from ...
 
Share this answer
 
Comments
[no name] 5-Jul-21 6:34am    
if i dont want that null value show in my class object how can i hide when its using an api response
[no name] 5-Jul-21 6:36am    
List<string> gradedemp = new List<string>(); its list object i am trying to convert in to json

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900