Sujeet Raman

Sujeet Raman

  • 1.4k
  • 895
  • 303.7k

How to return a formatted json list in c# Task method?

Jul 5 2021 8:36 AM

Hi, i have a method:

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?

public Task GetResultsEmployee(string  Id){
    ResultEmployee  ResultEmployee= new ResultEmployee();
    var Gradedemployeess= JsonConvert.SerializeObject(gradedemp); //issue 1
    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;  //issue 3
    result.Add(ResultSummary); //i have a list with other details
    return Task.FromResult(result); // issue 2

please help me on this

Answers (3)