Gordon Hickley Gordon Hickley - 1 month ago 5
JSON Question

JSON convert dictionary to a list of key value pairs

I have a Dictionary <string, string>

If I Json.Encode this I get


How I can get this to:-

[{ value: "Apples", key: "Apple" }, { value: "Oranges", key: "Orange"}]

Preferably using Newtonsoft.Json or jQuery


Convert it to a list of key value pairs before passing to the JSON serializer:

JsonConvert.SerializeObject(new List<KeyValuePair<string,string>>(dictionary));