Search code examples
c#jsonserializationjavascriptserializer

JavaScriptSerializer unexpected output


I use this example to serialize a dictonary like this

Dictionary<object, object>

What I get is

{ "key": "value" }

what I need is

{ key: "value" }

How do I get this output?


Solution

  • wrong approach - now I use a simple stringbuilder.

    foreach (DictionaryEntry entry in xSet)
    {
      result.AppendFormat("{0}: '{1}',", entry.Key, HttpUtility.JavaScriptStringEncode(entry.Value.ToString()));
    }