I have the following Dictionary<> object:
Dictionary<String, object> parameters = new Dictionary<string, object>(); parameters.Add("username", "mike"); parameters.Add("password", "secret"); parameters.Add("persist", false);
When I serialize it:
using (MemoryStream stream = new MemoryStream()) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(parameters.GetType()); serializer.WriteObject(stream, parameters); byte[] bytes = stream.ToArray(); string json = Encoding.UTF8.GetString(bytes, 0, bytes.Length); return json; }
I get the following:
"[{\"Key\":\"username\",\"Value\":\"mike\"},{\"Key\":\"password\",\"Value\":\"secret\"},{\"Key\":\"persist\",\"Value\":false}]"
What I want to get is a map of cards with a key / value, for example:
"{\"username\":\"mike\", \"password\":\"secret\", \"persist\": false}"
I tried setting UseSimpleDictionaryFormat to true, but this property has no effect, and its intended use is not documented anywhere else I can find.
I cannot use a custom class as parameter / parameter value pairs are not known at compile time.
I also cannot use a third-party library such as JSon.NET. I am using Silverlight and the Windows Phone 8 production environment.