How do I convert a dictionary to a JSON String in C#?

This answer mentions Json.NET but stops short of telling you how you can use Json.NET to serialize a dictionary:

return JsonConvert.SerializeObject( myDictionary );

As opposed to JavaScriptSerializer, myDictionary does not have to be a dictionary of type <string, string> for JsonConvert to work.

Leave a Comment