ASP.NET MVC4 Web API Controller should return json result which contains numeric propery names and values like
{ "openTimes":{"1":"09:00","2":"09:15","3":"09:30", ... }}
Propery names start with 1 . Number of properties and propery values are created in code. How to return such result ?
I tried controller
[HttpPost]
public class TestController : ApiController
{
public HttpResponseMessage Post()
{
return Request.CreateResponse(HttpStatusCode.OK, new {
openTimes = new { @"1"="09:00", @"2"="09:15", @"3"="09:30" }
});
}
}
but got compile error
Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
Also number of elements in list is determined at runtime. It is not fixed as in this sample. How to generate variable length list of property names "1", "2" and their values in code.
How to return such list from Web API ?