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 raw key/value pair map, like so:
"{\"username\":\"mike\", \"password\":\"secret\", \"persist\": false}"
I’ve tried setting UseSimpleDictionaryFormat to true, but this property has no effect nor is its intended use documented anywhere I can find.
I can’t use a custom class, since the parameter key/value pairs is not known at compile time.
I also cannot use a third party library, such as JSon.NET. I’m using the Silverlight framework and the Windows Phone 8 runtime.
Try serializing this