I used JSON.stringify() to store a javascript associative array of integer keys with boolean values in a cookie e.g. var arr = {}; arr[9000001] = True;. I can see the value of the string on the server in the following format: %7B%229000001%22%3Atrue%2C%229000003%22%3Atrue%2C%229000006%22%3Atrue%2C%229000009%22%3Atrue%7D where the first number is 9000001, second is 9000003, and so on.
I would like to use Json.Net to deserialize into a Dictionary<long,bool> or similar. I try the following
var result = JsonConvert.DeserializeObject<Dictionary<string, string>>(cookieValue);
but get the following exception
{"Unexpected character encountered while parsing value: %. Path '', line 0, position 0."}
I’m guessing deserialization is not possible in this scenario?
Frits van Campen found the missing piece. I wrote the following extension method that makes it easy to retrieve cookie values in C#. Set both
urlDecodeandfromJsontotrueand the object will be successfully deserialized.