I have following simple code which is giving list of employee , i have not added any formatter getting result in json array format.
I want it as a json object which has one defined key , how can i achieve this?
public HttpResponseMessage GetEmployee([FromUri(Name ="")]FilterEntity filters)
{
try
{
string contentType=Request.Headers.Accept.ToString();
if (String.Equals(contentType, Ecng_APIMsg.ContentType))
{
var empDetails = _empService.GetEMployee(filters.systemId, filters.pageIndex, filters.pageSize, filters.sortDirection);
if (empDetails != null)
{
return Request.CreateResponse(HttpStatusCode.OK, empDetails);
}
}
}
catch(Exception ex)
{
}
}
output-
[
{
"Id": 43,
"EmpId": 11
},
{
"Id": 42,
"EmpId": 12
}
]
expected
"data" : [
{
"Id": 43,
"EmpId": 11
},
{
"Id": 42,
"EmpId": 12
}
]
data must be there as a key of that json object.
I tried like below code to achieve this which is not working I'm missing something here -
var response = Request.CreateResponse(HttpStatusCode.OK, empDetails);
response.Content = new StringContent(response.ToString(), System.Text.Encoding.UTF8, "application/json");
return response;
empDetails is IEnumerable