Asp.Net Web Api - Return List of strings in JSON format

Viewed 34

I am creating an API which should return hardcoded list of strings, these list of strings will be used as column names in an excel template.

public IHttpActionResult GetExcelColumnNames()
{
  try
  {
    var columnNames = ""
  }
  catch(Exception ex)
  {
  }
}

can some one help on better way to return string list in json format which can be used from front end application and used as excel column names

1 Answers

Don't over think it, write your pseudo-code for what you want to achieve, then break it down into smaller steps, then transpose each step into real code

First thing you need to do is make your harcoded list of strings that you want to return:

string [] columnNames = new string [] { "FirstName", "LastName", "City", "State" };

Then, you can return them in an OkNegotiatedContentResponse, assuming this is an ApiController:

public IHttpActionResult GetExcelColumnNames()
{
    string [] columnNames = new string [] { "FirstName", "LastName", "City", "State" };
    return Ok(columnNames);
}
Related