Hey folks, hope you've all had a good break over the holidays.
I've created a WebService which returns a list of cities and companies within those cities as a JSON string using LINQ/JavaScriptSerializer.
My code is roughly
var data = from c in db.Companies
group c by c.City into cities
select new
{
city = cities.Key,
companies = from company in cities
select company.Name
};
JavaScriptSerializer jss = new JavaScriptSerializer();
return jss.Serialize(data);
That produces the following JSON string
[
{"city":"Auckland","companies":["Company1","Company2"]},
{"city":"Wellington","companies":["Company3","Company4","Company5"]}
]
However I want to make the city the key so I can easily search by it
For example
[
"Auckland" : {"companies":["Company1","Company2"]},
"Wellington" : {"companies":["Company3","Company4","Company5"]}
]
Any ideas?