views:

98

answers:

1

Hi,

I'm trying to convert a Dictionary in Silverlight to a string. I don't want to use any third-party libraries so would like to use System.Json to do this?

The best way I have thought of so far is to add all the items in the dictionary to a JsonObject and then call toString(), any better ideas would be most helpful.

+2  A: 
Dictionary<string, string> d = ...;

JsonObject jo = new JsonObject(
    from kv in d
    select new KeyValuePair<string, JsonValue>(
        kv.Key,
        new JsonPrimitive(kv.Value)));
string json = jo.ToString();
Pavel Minaev