0

I am using razor in webmatrix. I have a dictionary object

var occupancyTotalDic = new Dictionary<double, int>();

Once I have filled the dictionary with data I wish to output as JSON as a response to populate a flot chart

Dictionary<String, String> input = new Dictionary<String, String>();
occupancyTotalDic = input.ToDictionary(item => item.Key, item => (String)item.Value);

Response.ContentType = "application/json";
Response.Write(Json.Encode(occupancyTotalDic));

How do I convert my dictionary to contain strings so that I can output as JSON?

Cœur
  • 34,719
  • 24
  • 185
  • 251
user1222646
  • 113
  • 1
  • 1
  • 9

1 Answers1

0

Since Webmatrix can't compile MVC application I assume you are using ASP.NET webforms.

Tried this solution https://stackoverflow.com/a/5597628/713789

If you are using MVC then just use JsonResult test(){ return Json(myobj);}

Community
  • 1
  • 1
Anirudha Gupta
  • 8,670
  • 8
  • 52
  • 75