0

I try some way to return JSON but i am not able to do perfectly. Here is my Code

Public string GetData(){
  List<Test> result = new List<Test>();
  // Fill data from Database
  string isonData = JsonConvert.SerializeObject(result);
  return jsonData;
}
haldo
  • 14,512
  • 5
  • 46
  • 52

1 Answers1

2

You don't need to serialize it by hand. Just return the list directly:

public IEnumerable<Test> GetData(){
  List<Test> result = new List<Test>();
  // Fill data from Database
  return result;
}

Or better:

public IActionResult GetData(){
  List<Test> result = new List<Test>();
  // Fill data from Database
  return Ok(result);
}
Marcell Toth
  • 3,433
  • 1
  • 21
  • 36