In my ASP.net C# code, I have an IEnumerable container filled with objects of an anonymous type (which is loosely based on data from SQL).
Suppose that my code looks something like this:
var uics = entities.getData()
.Select(x => new
{
id = x.id
name = x.name
age = x.age
});
return Json(uics); //Serialize JSON in ASP.net MVC 3
This is very simple. When I serialize this to JavaScript, I get an array of objects, each having fields id, name, and age.
What I would like to do is serialize this data to a JavaScript Object with id as the index, with each object referenced by its index having fields name and age.
How can I accomplish this.
[ "id1" : {name: name1, age: age1} , "id2" : {name, name2: age: age2}]?